override on non-virtual functions

后端 未结 3 931
有刺的猬
有刺的猬 2020-12-09 08:51

The C++11 FDIS it says

If a virtual function is marked with the virt-specifier override and does not override a member function of a base class, the

相关标签:
3条回答
  • 2020-12-09 09:01

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

    0 讨论(0)
  • 2020-12-09 09:08

    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.

    0 讨论(0)
  • 2020-12-09 09:23

    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.

    0 讨论(0)
提交回复
热议问题