Why is it allowed to call derived class' private virtual method via pointer of base class?

前端 未结 6 1690
难免孤独
难免孤独 2020-12-15 07:35
# include 
using namespace std;

class A
{
    public:
    virtual void f()
    {
        cout << \"A::f()\" << endl;
    }
};
class B:pu         


        
6条回答
  •  悲&欢浪女
    2020-12-15 07:46

    Your base class is defining the interface for all the inherited children. I do not see why it should prevent the mentioned access. You can try deriving a class down from 'B' and use the Base interface to call , which would result in an error.

    Cheers!

提交回复
热议问题