I am studying C++ now. I am trying to study it from this link. Here in the 10th chapter, when I study about operator overloading, in an example program “*this” is returned as a constant reference. Here it is
Here in this program we are dereferencing the current object using “*this” and returning the value means the current Counter object as constant reference.
So when I do like this:
Counter a = ++i;
is the current object assigned to a constant reference and the value of the constant reference is copied to the new object created using default copy constructor ?
When you write
You’re simply copying from the
const Counter &being returned from the function. What you’re doing is equivalent to (from the point of view ofa):As long as you define
ato be aCounterobject, it will be created as a brand newCounterobject (Or you will get a compiler error if the copy-constructor is not accessible).