I wonder, why don't we use only this
without *
in case of an overloaded assignment operator? If I use this
only, it gives me a compiler error. Why we don't use *
with arr[i]
, or any other variables, like return x
in the 2nd and 3rd example?
Myclass &Myclass::operator=(const Myclass &rhs)
{
if(this==&rhs)
return *this;
}
double& setValues( int i ) {
return vals[i]; // return a reference to the ith element
}
int& setValues(int x) {
return x; // return address/reference of x
}