I am getting compile error C2064 for this code.
class MainClass;
class MyClass
{
public:
MyClass();
void (MainClass::*functionPointer)();
void callback();
};
class MainClass
{
public:
void testFunction();
void setup();
MyClass myClass;
};
void MainClass::testFunction()
{
}
void MainClass::setup()
{
myClass.functionPointer = &MainClass::testFunction;
myClass.callback();
}
void MyClass::callback()
{
functionPointer();
};
int main() {
MainClass mainClass;
mainClass.setup();
return(0);
}
I have tried:
- Changing the function call syntax to
this->functionPointer(); - Explicitly casting functionPointer to a regular function pointer with the code:
void (*fp)(void) = (void (*)(void))this->functionPointer; fp();
MainClassto call thefunctionPointerwith. YourMyClassdoes not have access to any such instance in the current code