Possible Duplicate:
C++ Returning reference to local variable
I am not able to pass the reference properly in the following code.
myint& myint::abs()
{
myint i=*this;
myint &t=i;
t.setsign(0);
return t;
}
The reference 't' is correctly modified in the abs() function. I have printed it and found that its correct. However the value received in main() is always wrong.
I have used the following statement in main()
myint a("-12"); /*gives a=-12 with each digit in a linked list node. separate data field for sign.*/
myint b=a.abs();
b received is 0, the default value.
Thanks in advance.