I've got the following code:
#include <iostream>
class Base{
private:
virtual void f(int) { std::cout << "f in Base" << std::endl; }
};
class Derived : public Base{
public:
virtual void f(int) { std::cout << "f in Derived" << std::endl; }
};
int main(void)
{
Base base;
Derived derived;
Base* p = &derived;
p->f(2);
return 1;
}
In base class f is decleared as private member function, and the
compiler complains that pointer p couldn't access private member in
base. It's clear that polymorph fails here. Why does it happen? Thanks
for help.