0

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?

Community
  • 1
  • 1
Buni
  • 251
  • 2
  • 13
  • It isn't that simple. If you `default`, say, the copy constructor, you don't get a default constructor any more. There are also rules concerning move constructors and move assignment operators. – juanchopanza Jun 06 '14 at 12:59

3 Answers3

0

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.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
0

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).

hl037_
  • 3,520
  • 1
  • 27
  • 58
0

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).

egur
  • 7,830
  • 2
  • 27
  • 47