I looked up on the forums and understood that & is used for effeciency and the whole object is passed as an argument rather than copied.
But I don't understand how in line 3 a is directly accessed without using the dot operator?
the member variables a, b and c are by default members of the object to which the copy constructor is being applied. For example:
1 2 3 4
CExample newObject(oldObject);
//oldObject is some existing object of type CExample.
// here the copy constructor is called and the following statements result:
//newObject.a = oldObject.a; similarly for other members.
CExample newObject;
newObject = oldObject; //oldObject is some existing object of type CExample.
// here the copy constructor is called and the following statements result:
//newObject.a = oldObject.a; similarly for other members.
No, the copy constructor is NOT being called here. Operator = is being called. If you wanted to call the copy constructor you would have to do something like this: