question from the tutorial

Here's the code of a default copy constructor of an object from the C++ tutorial:

1.CExample::CExample (const CExample& rv) {
2.a=rv.a; b=rv.b; c=rv.c;
3.}

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. 
Last edited on
1
2
3
4
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:

CExample newObject(oldObject);
sorry firedraco, my mistake. I have corrected my post
i got it... Thanks for the time :)
Topic archived. No new replies allowed.