How is it possible to override a private pure virtual function from the base class in the private section of a derived class? Like this:
class Person
{
private:
virtual int age() = 0;
};
class Baby : public Person
{
public:
void print_age() {
int a = age();
std::cout << a << std::endl;
}
private:
int age() override {
return 5;
}
};
int main()
{
Baby b;
b.print_age();
return 0;
}
It doesn't seem to make a lot of sence but it compiles and runs fine. Would it be best practice to make the private age() function protected instead?