S
sun1991
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;
}
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;
}