c++default-constructorimplicits

Conditions under which compiler will not define implicits (constructor, destructor, copy constructor, copy assignment)


This is supposed to be a trivial question but I could not find it explicitly on stackoverflow.

The following will be defined implicitly if not provided by the user.

  1. default (parameterless) constructor
  2. copy constructor
  3. copy assignment operator
  4. destructor

But I have read somewhere (which I cant seem to find now), that there are some conditions where the compiler will not implicitly implement them.

What are these conditions?


Solution

  • The Default Constuctor (e.g., X()) will not be implicitly generated if:

    The Copy Constructor (e.g., X(const X&)) will not be implicitly generated if:

    The Copy Assignment Operator (e.g., X& operator=(const X&)) will not be implicitly generated if:

    The Destructor (e.g., ~X()) will not be implicitly generated if:

    The Move Constructor (C++11) (e.g., X(X&&)) will not be implicitly generated if:

    The Move Assignment Operator (C++11) (e.g., X& operator=(X&&)) will not be implicitly generated if: