in c++ when subclassing why sometimes need to add virtual keyword to overridden function?

∥☆過路亽.° 提交于 2019-12-04 22:21:47

It is not necessary, but it helps readability if you only see the derived class definition.

§10.3 [class.virtual]/3

If a virtual member function vf is declared in a class Base and in a class Derived, derived directly or indirectly from Base, a member function vf with the same name and same parameter list as Base::vf is declared, then Derived::vf is also virtual (whether or not it is so declared) and it overrides 97) Base::vf.

Where footnote 97) basically states that if the argument list differs, the function will not override nor be necessarily virtual

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!