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() { }
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() {
}
Couldn't you clarify that thing?
See Question&Answers more detail:os