Skip to main content
gamedev.net
🔒 Locked

Passing a member method as a function pointer?

Started by biovenger 1 reply 650+ views
Original Post
biovenger
biovenger
I''ve already googled and checked function-pointer.org. Now that that''s out of the way, to the question. Is it possible to pass a member function (C++) to a C-style function that has a C-style function pointer as a parameter. Here is some code to simplify:
void SetFP((int (*fp)(void *));


class foo
{
public:
   int bar(void *);

   void foobar() { SetFP(bar); }  // How can I do this?

}
So far I''ve tried a lot of different syntax approaches and none have worked. Has anyone else encountered this problem or knows the answer to it?
-----------------------------Final Frontier Trader
biovenger
biovenger
Thanks for the quick reply. I''ll check out boost, didn''t know they had such features.

Also, I figured it out in another way, by using a static method that calls a private method through a void pointer. It''s a bit messy, but since the library C function I am using uses a pointer to a function that takes a void pointer. Thus I pass the static member function, in it I convert explicitly the pointer to a this-type and call the member method.
-----------------------------Final Frontier Trader

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.