Buni
Buni

Reputation: 251

C++ result of = default methods

Is there a way to actually see (output to file, console etc) implicit compiler generated or = default methods (in C++)?

(Target compilers: vc, clang, gcc)

I'd like to see how these functions are actually implemented. For example, how does the assignment operator assigns its values, does it check for self assignment, is const correctness given etc). I did not found any statisfying result on the www that actually shows the implementations of these compiler generated functions.

Upvotes: 1

Views: 159

Answers (1)

Niall
Niall

Reputation: 30605

The semantics of the "special member" functions are defined by the C++ standard, in section 12

In brief, they do what you think they do;

  • The default will invoke the defaults of the bases and the members
  • The copy will invoke the copy of the bases and members
  • The same applies for the moves, assignments and destructor

If, for some reason, one of them would violate a const correctness or the corresponding constructor or assignment of the base or members is not available, or some other issue arrises, then that special member is not declared.

An an additional note; there are specific rules that apply to the defaults if one (or some) of the special members are defined by the user (detailed here).

Upvotes: 1

Related Questions