I have a base class which has a method that takes a method pointer (class function pointer) as an argument. I derive a child class from this base class. I then want to pass a method of the child class to the method of the base class.
An example:
class Base1
{
public:
void BaseMethod(void (Base1::*basemth)(/*arguments list A*/),
double a)){/*definition*/}
};
class Derived1 : public Base1
{
public:
void ChildMethod(/*arguments list A*/)
void ChildMethod2()
{
double double_a = 1.0;
void (Derived1::*pntr)(/*arguments list A*/);
pntr = &Derived1::ChildMethod;
BaseMethod(pntr, double_a); //<---- this fails
}
};
I get "error: no matching function for call to...".
Is this possible? If it is, what am I doing wrong? Any help will be appreciated. I have looked at child class method pointer to method parent argument c++ but following R Sahu's method does not seem to work, while Slava's answer does not seem relevant (I am not calling a child method from a parent instance).