Possible Duplicate:
question about copy constructor
if I have this snippet of the code
A a1(i);
A a2 = a1;
A *pa1 = new A(a2);
can somebody please explain what exactly the last line does, it makes copy of the a2 and pointer for this new object is pa1 or it just creates pointer for a2, thanks in advance
The last line creates a new object A, to which pa1 points, and its contents are the same as those of a2.
I believe this example demonstrates the use of a constructor with arguments (first line), a copy constructor (second line) and another copy constructor (last line). In the end all the three object will have the same contents.