Overriding public virtual functions with private functions in C++

前端 未结 7 583
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 02:51

Is there is any reason to make the permissions on an overridden C++ virtual function different from the base class? Is there any danger in doing so?

For example:

7条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 03:39

    1. No technical problem, if you mean by technical as there being a hidden runtime cost.
    2. If you inherit base publically, you shouldn't do this. If you inherit via protected or private, then this can help prevent using methods that don't make sense unless you have a base pointer.

提交回复
热议问题