Public virtual function derived private in C++

前端 未结 3 723
离开以前
离开以前 2020-12-04 22:36

I was trying to figure out what happens when a derived class declares a virtual function as private. The following is the program that I wrote

#include 

        
3条回答
  •  佛祖请我去吃肉
    2020-12-04 23:16

    Well, you are calling A::func() which is public though in a B object it is overridden by B::func(). This is a common pattern with the following implications:

    • func is not intended to be called on derived B objects

    • func cannot be overridden in classes derived from B

提交回复
热议问题