default override of virtual destructor

前端 未结 7 1032
孤独总比滥情好
孤独总比滥情好 2021-02-01 12:50

Everyone knows that the desructor of base class usually has to be virtual. But what is about the destructor of derived class? In C++11 we have keyword \"override\" and ability t

7条回答
  •  情深已故
    2021-02-01 13:16

    Though destructors are not inherited there is clear written in the Standard that virtual destructors of derived classes override destructors of base classes.

    From the C++ Standard (10.3 Virtual functions)

    6 Even though destructors are not inherited, a destructor in a derived class overrides a base class destructor declared virtual; see 12.4 and 12.5.

    On the other hand there is also written (9.2 Class member)

    8 A virt-specifier-seq shall contain at most one of each virt-specifier. A virt-specifier-seq shall appear only in the declaration of a virtual member function (10.3).

    Though destructors are called like special member functions nevertheless they are also member functions.

    I am sure the C++ Standard should be edited such a way that it was unambiguous whether a destructor may have virt-specifier override. At present it is not clear.

提交回复
热议问题