For C ++ 11 code, the accepted answer by @Alper is fine. Please note that from the point of view of Clang 3.7 (I donโt know which version of Apple that matches, of course, you can find out) using -std=c++1z -Wdeprecated , you will create the following
warning: definition of implicit copy constructor for 'TestClass' is deprecated because it has a user-declared destructor [-Wdeprecated] ~TestClass() ^
Live example
The relevant part of the C ++ 1z Standard N4567 project is
12.8 Copying and moving class objects [class.copy]
7 If the class definition does not explicitly declare the copy constructor, the implicit one is declared implicitly. If a class definition declares a move constructor or a move carry operator, an implicitly declared copy constructor is defined as deleted; otherwise, it is defined as default (8.4). The latter case is deprecated if the class has a user-declared copy assignment operator or a user-declared destructor .
Obsolete means that the future Standard may stop generating an implicit copy constructor in case of a user-declared destructor. It is best to change your code today so as not to rely on obsolete behavior (i.e., in this case, making the instance behavior of your class explicit).
source share