dimanche 21 août 2016

Implicitly-generated constructors with explicit declaration of destructor

The thing is, 4th edition of C++ Programming language says:

In this particular case, if you forgot to delete a copy or move operation, no harm is done. A move operation is not implicitly generated for a class where the user has explicitly declared a destructor. Furthermore, the generation of copy operations is deprecated in this case (§44.2.3). This can be a good reason to explicitly define a destructor even where the compiler would have implicitly provided one (§17.2.3).

I've tried this code:

#include <iostream>
class Foo {
public:
    ~Foo() {}
}
int main() {
    Foo x;
    Foo y(x);
    return 0;
}

and there is no errors and exeptions here. I know that copy constructor should be generated implicitly in c++98, but 4th says that copy is deprecated. What does it mean?

Aucun commentaire:

Enregistrer un commentaire