Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I inspect the default copy/move constructors/assignment operators?

How do I find out what exactly my classes’ default constructors, destructors, and copy/move constructors/assignment operators do?

I know about the rule of 0/3/5, and am wondering what the compiler is doing for me.

If it matters, I’m interested in >=C++17.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The implicitly-defined copy constructor

… performs full member-wise copy of the object’s bases and non-static members, in their initialization order, using direct initialization

For a simple structure:

struct A
{
    int x;
    std::string y;
    double z;
};

The copy-constructor would be equivalent to:

A::A(A const& otherA)
    : x(otherA.x), y(otherA.y), z(otherA.z)
{
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading