Hi, it is my first post here~ :). I find this website very useful and I am often using it to solve my c++ problems!
Anyway I was not able to find how to pass an instance method to a constructor of the superclass.
Below is the code I am working on:
class Base{
public:
int (*funky) (void);
Base(int (*funkyName) (void)){
this->funky = funkyName;
}
virtualvoid callfunky(){
cout << "value: " << funky() << '\n';
}
};
class Derived: public Base{
public:
int myFunkyTranky(){
return -1;
}
Derived(): Base(myFunkyTranky){
}
};
The problem is in the constructor of the class 'Derived', where I try to give as argument an instance method of the same class.
The compiler generates the following error: no matching function for call to 'Base::Base(<unresolved overloaded function type>)'
Is there any way to achieve this functionality in C++?