Why am I permitted to declare an object with a deleted destructor?

前端 未结 4 1382
甜味超标
甜味超标 2021-01-01 13:59

Consider the following text:

[C++11: 12.4/11]: Destructors are invoked implicitly

  • for constructed objects with static
4条回答
  •  执念已碎
    2021-01-01 14:38

    Accessibility is orthogonal to deletedness:

    [C++11: 11.2/1]: If a class is declared to be a base class (Clause 10) for another class using the public access specifier, the public members of the base class are accessible as public members of the derived class and protected members of the base class are accessible as protected members of the derived class. If a class is declared to be a base class for another class using the protected access specifier, the public and protected members of the base class are accessible as protected members of the derived class. If a class is declared to be a base class for another class using the private access specifier, the public and protected members of the base class are accessible as private members of the derived class.

    There is this:

    [C++11: 8.4.3/2]: A program that refers to a deleted function implicitly or explicitly, other than to declare it, is ill-formed. [ Note: This includes calling the function implicitly or explicitly and forming a pointer or pointer-to-member to the function. It applies even for references in expressions that are not potentially-evaluated. If a function is overloaded, it is referenced only if the function is selected by overload resolution. —end note ]

    But you never "refer to" the deleted destructor.

    (I still can't explain why the inheritance example doesn't compile.)

提交回复
热议问题