Why do I explicitly declare classes as special functions by default,

What is the difference between explicitly declaring special class functions by 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 these two ads? Why explicitly specify default behavioral functions by default?

+4
source share
1 answer

Because, under certain conditions, the compiler may not add constructors, destructor or operators, even if you may need the default parameters created by the compiler. Then, using an explicit pointer default, the compiler will do it anyway.

, . class .

+8

Source: https://habr.com/ru/post/1679252/


All Articles