Monday, July 1, 2019

c++ - What is the point of deleted destructor?

I come across the rule (section N3797::12.8/11 [class.copy])




An implicitly-declared copy/move constructor is an inline public
member of its class. A defaulted copy/ move constructor for a class X
is defined as deleted (8.4.3) if X has:



[...]




— any direct or virtual base class or non-static data member of a type
with a destructor that is deleted or inaccessible from the defaulted
constructor, or



[...]




But I can't get the point of deleted destructor appearing in a virtual or direct base class at all. Consider the following simple example:



struct A

{
~A() = delete;
A(){ }
};

struct B : A
{
B(){ }; //error: use of deleted function 'A::~A()'
};


B b;

int main() { }


DEMO



It's perfectly unclear to me. I defined 0-argument constructor explcitly and it doesn't use base class destructor. But compiler thinks otherwise. It won't work even if we define B's destructor explicitly:



struct A

{
~A() = delete;
A(){ }
};

struct B : A
{
B(){ };
~B(){ };
};


//B b;

int main() {
}


DEMO



Couldn't you clarify that thing?

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...