I recently come to this thought, and did a test:
class B1
{
public:
virtual void Func()
{
std::cout << "Here is B1" << "\n";
}
};
class B2: public B1
{
private:
virtual void Func()
{
std::cout << "Here is B2" << "\n";
}
};
class B3: public B2
{
public:
virtual void Func()
{
std::cout << "Here is B3" << "\n";
}
};
int main()
{
B1* pB2 = new B2();
B1* pB3 = new B3();
pB2->Func();
pB3->Func();
delete pB2;
delete pB3;
return 0;
}
---
Func() in class B2 is under private tag, but seems it has no problem
to be called in main(), why? Is that means when polymiorphism, the
access privilege is just up to base class?