hey,
i'm having trouble working out what the syntax is when you want to pass a member function of a class (from a another member function of that class) to another function (which is a member of another class)...
like this:
Code:
typedef void(*FnToCallback)(void);
class B
{
public:
void Register(FnToCallback passedInFnToCallback);
void FnThatCallsBackLater();
private:
FnToCallback storedFnToCallback;
};
class A
{
public:
A(B classToRegisterTo);
void CallbackFunction();
};
B instanceOfB;
A instanceOfA(instanceOfB);
A::A(B classToRegisterTo)
{
classToRegisterTo.Register(CallbackFunction);
}
void A::CallbackFunction()
{
//does something useful
}
void B::Register(FnToCallback passedInFnToCallback)
{
storedFnToCallback = passedInFnToCallback;
}
void B::FnThatCallsBackLater()
{
storedFnToCallback()
}
int main()
{
//lots of code
instanceOfB.FnThatCallsBackLater();
//more code
}
i think that makes sense
anyway, as it stands, i get an error like this:
cannot convert parameter 1 from 'void (void)' to 'void (__cdecl *)(void)'
i think the problem is that i am trying to pass a pointer to a member function, because if i create a test global function and try to pass that, it works.
thanks in advance to anyone who can decipher all that and help