#include <iostream>
class virtualClass{
public:
virtual int a() = 0;
};
class UnknownImplementation : public virtualClass{
public:
int a() override { return 1;}
};
class myFramework {
public:
int c(int (virtualClass::*implementedFunc)(void)){
implementedFunc();
return 2;
}
};
int main(){
//some user implements the virtual class and calls myFramework function
myFramework* mfp = new myFramework();
std::cout << mfp->c(&(UnknownImplementation::a)) << std::endl;
}
Hi, I am working on a framework that is supposed call an implemented virtual function and use it. It is similar to the code above. The compiling errors I get are:
testVirtual.cpp: In member function ‘int myFramework::c(int (virtualClass::)())’: testVirtual.cpp:16:19: error: must use ‘.’ or ‘->’ to call pointer-to-member function in ‘implementedFunc (...)’, e.g. ‘(... -> implementedFunc) (...)’ implementedFunc(); ^ testVirtual.cpp: In function ‘int main()’: testVirtual.cpp:24:47: error: invalid use of non-static member function ‘virtual int UnknownImplementation::a()’ std::cout << mfp->c(&(UnknownImplementation::a)) << std::endl;
How do I fix these problems? Thanks in advance!
passing an instance of the implemented class and calling the function worked.