I am currently playing around with pointer to member functions but am currently having trouble getting them to work with inheritance. Is it possible to define a member function which takes a pointer to another member function which can exist only in a derived version of the class?
This is my current code:
It does not compile as call expects a pointer to one of basecls's member functions. However it is possible to do something functionally equiv to this?Code:#include <iostream> using namespace std; class basecls { public: typedef void (basecls::* fPtr) (float); void call (fPtr mPtr) { (this->*mPtr)(10); } void foo (float x) { cout << x << endl; } }; class derivcls : public basecls { public: void bar (float x) { cout << x * 2 << endl; } }; int main () { derivcls b; b.call(&derivcls::bar); return 0; }
Regards, Freddie.