Misunderstanding of "copy constructor" and "Copy copy": ---- "=" syntax can also be used to call the copy constructor:
For example, constr object3 = object1;
The difference is that if a new object (such as constr object3) is defined, a constructor will be called and it is impossible to call the copy operation.
If no new object is defined (such as object1 = object2;), no constructor is called. Of course, you are calling the "Copy copy" operation!
Sample Code:
# Include <iostream>
# Include <vector>
# Include <algorithm>
Using namespace STD;
Class constr
{
Public:
Constr ()
{
Cout <"constr ()" <Endl;
}
Constr (const constr & con)
{
Cout <"constr (const constr & con)" <Endl;
}
Constr & operator = (const constr & con)
{
Cout <"constr & operator = (const constr & con)" <Endl;
Return * this;
}
};
Int main ()
{
Constr object1;
Constr object2 (object1 );
Object1 = object2;
Constr object3 = object1;
Return 0;
}
Copy construction and Copy Replication