Is this a operator overloading bug?

Oskar Linde oskar.lindeREM at OVEgmail.com
Thu Jan 11 06:31:09 PST 2007


mike wrote:
> Am 11.01.2007, 15:07 Uhr, schrieb Tim Fang <no at spam.com>:
> 
>> I have called "a.set(1,1,1)" to init the members in main().
> 
> Yeah, but
> 
>>>>  Vector3 opMul(float s)
>>>>  {
>>>>   Vector3 ret;
>>>>   ret.x = x*s;
>>>>   ret.y = y*s;
>>>>   ret.z = z*s;
>>>>   return ret;
>>>>  }
> 
> creates a new, uninitialized Vector3 and returns it. This should work:

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".

As Bill Baxter said, this is a bug introduced in DMD 0.178.

/Oskar



More information about the Digitalmars-d mailing list