What is the difference between explicitly declaring classes special functions default.
class Myclass
{
public:
Myclass() = default;
virtual ~Myclass() = default;
Myclass(MyClass&&) = default;
Myclass& operator=(MyClass&&) = default;
Myclass(const MyClass&) = default;
Myclass& operator=(const MyClass&) = default;
};
MyClass{};
What is the difference between this 2 declarations? Why explicitly specify the default behavioral functions as default??
Because under certain conditions the compiler might not add the constructors, destructor or operators even though you may want the compiler-generated defaults. Then by using the explicit default
designator the compiler will do that anyway.
You can find out more in e.g. this class
reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With