An example:
class Base
{
protected:
virtual void function() { std::cout << "Base\n"; }
void callfunction(void (Base::* func)()) { (this->*func)(); }
};
class Derived1 : public Base
{
public:
void publicCall() { callfunction(&Derived1::function); }
private:
void function() override { std::cout << "Derived1\n"; }
};
I would like to be able to send the derived function pointer to the base class to fulfill a pattern that can be specified in the base class. Thus, reusing code.
However, I'm not sure what the type is supposed to be in the base class since Base::* is not a Derived1::*.
I get the following error:
No instance of overloaded function callfunction matches the argument list: arguments types are (Derived1::*)
Now obviously, I could change the data type to be Derived1::*
, but that wouldn't allow me to send in other derived class virtual functions back to Base
to handle, such as Derived2::function()
Can a template sort of function be created like this?