There is a difference between constructing a new object and assigning a new value to an existing object.
Code:
class A {};
void func()
{
A first; // calls default constructor to make a new A called first.
A copy_of_first( first ); // calls copy constructor to construct a new A thats a direct copy of first.
A second;
first = second; // this is assignment. We dont create first, we just give it a new value
A third = second; // this is initialisation. Its a copy constructor call.
}
I hope that clears things up a bit.
Bookmarks