-1

C++11 introduced new keyword default to force creation of default constructor:

class MyClass {
    MyClass() = default; // <==
    MyClass(int num);
};

I could not find the reason to use it over empty constructor.

class MyClass {
    MyClass() {} // <==
    MyClass(int num);
};

Could anybody enlighten me?

StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458
Ronny Sherer
  • 8,349
  • 1
  • 22
  • 9

1 Answers1

7

The = default; constructor is trivial, which no user provided constructor ever is - even an empty one.

acraig5075
  • 10,588
  • 3
  • 31
  • 50
Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70
  • 1
    It might be also be important to note that a `= default;` constructor is `constexpr` and/or `noexcept` by default if it is possible. – DeiDei Apr 24 '18 at 10:30