Difference between =default and empty constructor with no arguments?
Is there difference between:
MyClass() {}
MyClass() = default;
Difference between =default and empty constructor with no arguments?
Is there difference between:
MyClass() {}
MyClass() = default;
Overall No there is not. ;)
It will do overall the same, but not exactly (like sftrabbit, Nawaz, and 0x499602D2 suggest it, thanks by the way).
You will find an answer to your question here ;)
So, this does not use constructors, but destructors. But it does show a point. The following code will compile, and no static assertions will fire.
This means that you have a user defined destructor in one example, and a __default destructor in the other.
#include <type_traits>
class X {
public:
~X() {}
};
class Y {
public:
~Y() = default;
};
static_assert(std::is_trivially_move_constructible<X>::value == false, "");
static_assert(std::is_trivially_move_constructible<Y>::value == true, "");