jeudi 19 avril 2018

Pro and Cons of always declaring defaulted constructors

What are the pro and cons of declaring always defaulted constructors for each non user-defined constructor?

Consider a class with a user-defined constuctor which does not need other user-defined constructors, it would be:

class Foo
{
public:
   Foo() { // user-defined declaration }
   Foo(const Foo&) = default;
   Foo(Foo&&) noexcept = default;
   ~Foo() = default;
}

Pro:

  • Let the reader aware of you did not forget or not considered the option of using other constructor.

Cons:

  • Increase verbosity.

There are other actual advantages/disadvantages of doing that?

Aucun commentaire:

Enregistrer un commentaire