Is this a operator overloading bug?
Tim Fang
no at spam.com
Thu Jan 11 06:52:36 PST 2007
' Vector3 opMul(float s)
' {
' Vector3 ret; // <-- creates new, and
' ret.x = x*s; // <-- oh, wait a sec ... this x should be initialized
-- x is the member of "Vector3 a", which is declared and initialized in
"main()".
' ret.y = y*s;
' ret.z = z*s;
' return ret;
' }
'}
"mike" <vertex at gmx.at> wrote :op.tlzu9adrnxkcto at zimmermoos...
Am 11.01.2007, 15:31 Uhr, schrieb Oskar Linde
<oskar.lindeREM at OVEgmail.com>:
> It creates a new default-initialized Vector3, *initializes* it and
> returns it. I don't see anything wrong with the code. The result of the
> original code should be "222", not "nannannan".
Yes, but the default initializer for float is NaN, so:
' Vector3 opMul(float s)
' {
' Vector3 ret; // <-- creates new, and
' ret.x = x*s; // <-- oh, wait a sec ... this x should be initialized
' ret.y = y*s;
' ret.z = z*s;
' return ret;
' }
'}
Now I'm confused ... :)
Maybe it's really a bug.
-mike
--
Erstellt mit Operas revolutionärem E-Mail-Modul: http://www.opera.com/mail/
More information about the Digitalmars-d
mailing list