OOPS 5 Copy Constructor

In the video OOPS 5 Copy Constructor, Prateek Sir said that when we call the copy constructor by reference it basically points to the same object like an alias of that object which is passed by reference in the copy constructor parameter. But if this is the case that both objects are pointing to same area, how is it possible that we can change the variable values of one object without affecting the values of other object? I think this can happen only if we store separate copies of the 2 objects involved in this process.
Please resolve my doubt.

hello @rahul.maheshmaheshwari

it depends on implementation of copy constructor.
see we are passing the object as reference but we are copying it by value only.

class a{

public:
int x;
a( a &obj){ // object is passed as reference
x=obj.x; // here only value is copied we are not creating any reference.
}

};

Yes that is my doubt that if we are passing object as reference how is it possible that we can change value of one object without affecting other as passing by reference means that we are not creating a new object and just pointing to a existing one.

check my above example, there we are copying value(properties of member variable)

of passed object .

ok thanks for the resolve.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.