Unlike virtual member functions, I need a solution in which a function implemented in each derived class of a level can be registered for subsequent call by the base class. (Not only the most derived implementation)
To do this, I was thinking of providing a mechanism for derived classes to register their functions with the base class, for example, during the constructor of the derived class.
I'm having problems with a member function pointer argument. I thought Derived was derived from Base, the this pointer should be automatically started.
Can this be done close to what I'm trying, or do I need to use static member functions, void * and static_cast ?
class Base { protected: typedef void (Base::*PrepFn)( int n ); void registerPrepFn( PrepFn fn ) {}; } class Derived : public Base { Derived() { registerPrepFn( &Derived::derivedPrepFn ); }; void derivedPrepFn( int n ) {}; }
Compiler Error:
error: no matching function for call to 'Derived::registerPrepFn(void (Derived::*)(int))' note: candidates are: 'void Base::registerPrepFn(void (Base::*)(int))'
c ++ member-function-pointers
NoahR
source share