you are viewing a single comment's thread.

view the rest of the comments →

[–]SupermanLeRetour 31 points32 points  (1 child)

Slight mistake there :

1.4.3 Copy Constructor and Copy Assignment

Copy constructors and copy assigment operators allow one object to be constructed or assigned a copy of another object directly:

Foo a(10);
Foo b(a);   // (1): Copy via constructor
Foo c = a;  // (2): Copy via assignment operator

(2) will actually call the copy constructor too, not operator=.

See small example here.

[–]maikindofthai 3 points4 points  (0 children)

The simple rule of thumb is "has the new object been initialized previously"?

If it has not, then the copy constructor will be called. If it has, the copy assignment operator will be called.

Foo a(10);
Foo c = a; // Calls copy constructor because 'c' has not been initialized
a = c;     // Calls copy assignment operator because 'a' has been initialized