C++11 interface pure virtual destructor

前端 未结 3 1715
攒了一身酷
攒了一身酷 2021-02-09 03:37

UPD. There is a mark that it is a duplicate of this question. But in that question OP asks HOW to use default to define pure virtual destructor. Th

3条回答
  •  灰色年华
    2021-02-09 04:02

    All I could find was:

    §12.4 (5.9)

    A destructor can be declared virtual (10.3) or pure virtual (10.4); if any objects of that class or any derived class are created in the program, the destructor shall be defined. If a class has a base class with a virtual destructor, its destructor (whether user- or implicitly-declared) is virtual.

    leading to:

    §10.4 (the class is now abstract)

    10.4 (2) says:

    A pure virtual function need be defined only if called with, or as if with (12.4), the qualified-id syntax (5.1).

    But the narrative on destructors in §12.4 talks about destructors always being called as if by their fully qualified name (in order to prevent ambiguity).

    Which means that:

    • the destructor must be defined, even if pure virtual, and

    • the class is now abstract.

提交回复
热议问题