The function takes as a parameter a pointer to a member function of the base class. How to call this function, passing it the necessary pointer to the corresponding member function?
Example:
void MyClass::func(void(*fptr)()){ for(size_t i = 0; i < items.size(); i++){ for(size_t q=0; q<nit.size();q++){ (items[i]->*nit[q])(); } } } void MyClass::fill1(){ func(void(*fill)()); } void MyClass::delete1(){ func(void(*delete)()); }
The fact that heder:
typedef void (Base::*fptr)(); std::vector<fptr> nit; MyClass(){ fptr delete=&Base::delete; fptr fill=&Base::fill; nit.push_back(delete); nit.push_back(fill); }
The compiler throws the following error: invalid use of member function (did you forget the "()"?) Func (void (* delete) ()); func (void (* fill) ());
func
doesn't use the argument passed at all, this time. And secondly, in the definition offunc
fptr
is not a typedef type, but a local variable name. What shouldfunc
actually do? - VladDfunc
not needed? - VladD