<pre class="bz_comment_text" id="comment_text_0" style="font-size:small;font-family:monospace;white-space:pre-wrap;width:50em;color:rgb(0,0,0);font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255)">
For the given test:
class A1 {
int x;
int y;
public:
A1(int a, int b)
{
x=a;
y=b;
}
A1 operator+(const A1&);
};
A1 A1::operator+(const A1& second)
{
A1 sum(0,0);
sum.x = x + second.x;
sum.y = y + second.y;
return (sum);
}
int main (void)
{
A1 one(2,3);
A1 two(4,5);
return 0;
}
when the exectable of this code is debugged in gdb for i386, we dont get the
expected results.
when we break at return 0; and give the command: print one + two, the result
should be $1 = {x = 6, y = 8}, but the result obtained is $1 = {x = 2, y = 3}.
This is related to debug information generated, as normally the overloading is
occuring.
eg: A1 three = one + two results {x = 6, y = 8}.
On checking the assembly, a suspicious entry is found which may be related for
the failure:
#DEBUG_VALUE: operator+:this <- undef
#DEBUG_VALUE: operator+:second <- undef</pre><br clear="all"><br>-- <br><div>Thanx & Regards <br></div>
<div><b>Mayur Pandey </b><br></div><br><div><font color="#3333ff"> <br></font></div>
<div> </div>
<div> </div><br>