When declaring a class/struct/union the compiler will generate the default methods (rule of three). This also will happen when = default
'ing these methods.
How do the default methods exactly look like?
When declaring a class/struct/union the compiler will generate the default methods (rule of three). This also will happen when = default
'ing these methods.
How do the default methods exactly look like?
For example let consider the default constructor. According to the C++ Standard
An implicitly-declared default constructor is an inline public member of its class.
and
The implicitly-defined default constructor performs the set of initializations of the class that would be performed by a user-written default constructor for that class with no ctor-initializer (12.6.2) and an empty compound-statement.
So it looks like
struct A
{
A() {}
};
except that it is not explicitly declared and defined.
About copy constructor you can read at my personal forum
http://cpp.forum24.ru/?1-1-0-00000021-000-0-0-1388485669
Though it is written in Russian but you can translate it for example using google service translate.
For each of these methods, the compiler defines default inline methods that call the default methods of each attribute of the object. (so a pointer won't be initialized neither any built-in type).
Those method will do the minimum necessary to initialize the class.
Default construtor - do nothing with simple members but call the constructors of more complex members (class/struct) as well as call the ctor of its super class.
Copy constructor will perform a shallow copy (memcpy).