copy constructor is deprecated if copy assignment operator or the destructor is user-declared ????

I do not understand how a copy ctor can be deprecated when either of the special functions mentioned is user declared...

How can the compiler create the copy ctor from the destructor for instance?
From the assignment operator that seems doable but not from the destructor.

Any light on this?

Thanks

Juan
Currently the C++ compiler will write a copy constructor and copy assignment operator for you if you provide a destructor. This behavior is deprecated, but copy constructors aren't deprecated otherwise.

The intent is to support the rule of three
https://en.cppreference.com/w/cpp/language/rule_of_three
Which implies that if a class needs a user-declared destructor, it needs to have "custom" copy functions or have no copy functions at all.

See [depr.impldec]
http://eel.is/c++draft/depr.impldec
Last edited on
Registered users can post here. Sign in or register to post.