I'm trying to set a pointer to a member function from another class, but I can't figure out how to do this. I have three classes: Control, Button, Textbox. Button and Textbox have their own void _Draw(), and the Control class has a pointer to void (*drawFunc(int))
I want both Button and Textbox classes having access to Control _drawFunc pointer to set it as their _Draw functions.
void Draw1(int t) {
printf("%d\n", t);
}
struct Control {
void (*drawFunc)(int);
Control() {}
};
struct Button : Control{
void _Draw(int m) {
// ...
}
Button() {
drawFunc = &Button::_Draw; // Draw1 works fine
}
};
struct Textbox : Control{
void _Draw(int m) {
// ...
}
Textbox() {
drawFunc = &Textbox::_Draw; // Draw1 works fine
}
};