override on non-virtual functions

旧时模样 提交于 2019-11-28 08:04:56
Armen Tsirunyan

What if B::f would not have been marked virtual? Is the program ill-formed, then?

Yes, it is. Because in order to override something, that something has to be virtual. Otherwise it's not overriding, it's hiding. So, the positive answer follows from the quote in your question.

If B:f was non-virtual, then both D:f functions would be ill-formed.

Yes, the program is ill formed when override is added to any non-virtual function.

Generally, functions with differing signatures (overloaded), are as different as functions with different names. The example given in the Spec is not meant to imply that the function name effects override. It's meant to show the common error that override is designed to prevent.

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