I have this compile error because of polymorphisme (i guess)
error: no matching function for call to ‘derived::print()’
:
#include <iostream>
class base{
public:
void print()
{
print("Hello from ");
}
private:
virtual void print(const std::string & message)
{
std::cout << message << " base class !! n";
}
};
class derived: public base{
private:
void print(const std::string & message) override
{
std::cout << message << " derived class !! n";
}
};
int main()
{
base b;
b.print();
derived d;
d.print();
return 0;
}
What is the best solution without renaming the method print
neither duplicate it in the derived class ?
1