Skip to main content
GameDev.net gamedev.net
🔒 Locked

converting Member function pointers to nonmember function pointers.

Started by xria Aug 3, 2002 at 5:56 PM 3 replies 350+ views
Original Post
xria
xria
I have a function that takes a bool(*)(void) function pointer as a paramenter, and I need to pass a class instance''s member function of the same type into this parameter. class MYCLASS { public: bool Function(); }; MYCLASS Testclass; I need to pass TestClass.Function as a bool(*)(void). Kinda stumped on that one.
m_w_noname
m_w_noname
You can''t really pass an function pointer to an instance of an object. The best you can do is make a member func static and pass that...

class MyClass
{
public
static bool Function();
}

then you can pass it, but you don''t know which instance of an object your talking about.
xria
xria
Shit. Thanks for the links and advice, it cleared it up for me pretty easily. Looks like it''s time to go redesign my gui class....
sark
sark
You might wanna look into adaptable functors with templates. You can do all sorts of cool things with them. Its quite an advanced topic, so if you still consider yourself a newbie then i'ld advise you stick to function pointers

[edit] assuming you arent going to pass the function pointer to functions you didnt make, of course.

[edited by - sark on August 3, 2002 10:11:28 PM]

Topic Locked

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

Sign in to reply to this topic.