vendredi 7 décembre 2018

=default on copy control members

"Beginner to C++"

Why do so many classes use =default for the copy constructor and assignment operator and on their non-virtual destructors?

How is

class A{
public:
    A() = default;
    A(int);
};

different from

class A{
public:
    A() = default;
    A(int);
    A(const A&) = default;
    A& operator=(const A&) = default;
    ~A() = default;
};

My understanding is that even without these =default, these operations will be synthesized.

Aucun commentaire:

Enregistrer un commentaire