I had a small clarification about overloaded pre-increment operator.
I am returning the object by reference in the definition for pre-increment overloading.
Object obj1;
Object obj2 = ++obj1
1) Isn't it true that obj2 refers to obj1 after second line is executed ?
a) If yes, why does changing the value of obj2 doesn't change the value
of obj1 ?
b) If no, does the statement "retrun *this" creates a new object with
same state as object pointed by this pointer and returns that object.
1) Isn't it true that obj2 refers to obj1 after second line is executed ?
It is not true. The variable obj2 is not a reference; references are declared with &. Object& obj2 = ++obj1;
b) If no, does the statement "return *this" create a new object with
same state as object pointed by this pointer and returns that object.
No: it returns a reference to the current object. A copy is made, but it happens a little bit later, during the initialization of obj2 from the value of the expression ++obj1.