Ok here is pseudo-code showing the problem. I want to pass on the Man's sayAh() method to the Dog instance.
class Man
{
public:
void haveDogBiteYou(){
Dog *mydog = new Dog();
myDog->setCallback(&this->sayAh); // How???
myDog->bite();
}
void sayAh(){
cout << "AHHHHHH!";
}
}
class Dog{
public:
void (*callbackFunc)(void);
void setCallback(void (*callbackFunc)(void)){
this->callbackFunc=callbackFunc;
}
void bite(){
callbackFunc();
}
}
I'd like to have the code setup in a way that if I have another class like Kid (i.e., Man's subclass), I can pass on the callback to a method member of that function as well. So probably changing
void (*callbackFunc)(void);
to
void (Man::*callbackFunc)(void);
will not be an answer to this problem... By the way, I am open to other solutions... Something like Java's interface works great.