The function signatures for prefix and postfix are different, so if you can tell them apart, the compiler sure can. Is loc operator-- ( int ); completely the same as loc operator-- ( ); ? Now all you need to know is which does what operation.
I am confused:
I got 2 example functions which returns "*this".
one of them is like:
Code:
class_name & fun_name (class_name);
the other one is:
Code:
class_name fun_name (class_name);
if it is "return(*this)" in both of them , how come the return type is different?!
I believe because it is a reference can be treated like the object itself, so the compiler wouldn't mind?
Although if it was a pointer, it would very much mind
You ended that sentence with a preposition...Bastard!
loc loc::operator--(int)
{
loc temp=*this;
lenght--;
width--;
return (temp);
}
will solve the problem.
"this" points to the current obj.
Before changing anything, copy it into temp.
by
lenght--;
width--;
the object will be changed but the previous value is returned by return(temp).
I don't get it.
You do not update the object however?
so how will it get updated when you return temp?
unless you do
obj1=--obj1 :S
You ended that sentence with a preposition...Bastard!