bool functionImplementation(int& a) {
a++; // Just increments the parameter
}
FunctionPointerType getFunctionPointer() {
return functionImplementation;
/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: cannot convert 'MainClass::functionImplementation' from type 'bool (MainClass::)(int&)' to type 'MainClass::FunctionPointerType {aka bool (MainClass::*)(int&)}'
*/
}
public:
void run() {
FunctionPointerType t = MainClass::getFunctionPointer;
/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: cannot convert 'MainClass::getFunctionPointer' from type 'bool (MainClass::* (MainClass::)())(int&)' to type 'MainClass::FunctionPointerType {aka bool (MainClass::*)(int&)}'
*/
^
bool functionImplementation (int& a)
{
a++; // Just increments the parameter
returntrue; //you promised to return something, then you ought to return something
}
FunctionPointerType getFunctionPointer ()
{
return &MainClass::functionImplementation; //taking the address
}
public:
void run ()
{
FunctionPointerType t = this->getFunctionPointer(); //calling the function, `this' is optional
}