4.8 Constructors

Always try to provide a default constructor if possible.

Always try to initialize variables with their declaration.

Delegating constructors is much faster than using assignment.

Foo(const unsigned int f, const bool b) : foo(f), bar(b) {}

Always follow the rule of three: if you include one of the following, you have to include all of them.

  • Constructor
  • Destructor
  • Copy constructor

In virtual classes, always declare the destructor virtual.

Aggregate initialization for structs is great. Use them.

Not required, but declaring your constructor noexcept is good practice.

When extending a class, always make sure to call super() unless the documentation explicitly tells you not to.

results matching ""

    No results matching ""