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

前端 未结 6 1693
难免孤独
难免孤独 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:54

    Pretty much like in Java, in C++ you can increase the visibility of methods but not decrease it.

提交回复
热议问题