|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D.learn - Difficulty with operator overloading opMulAssign
DMD 1 reports an error for the struct below, marked "// Error":
math/vector.d(35): Error: incompatible types for ((this) *= cast(float)1
/ m)): 'Vector3 *' and 'float'
math/vector.d(35): Error: 'this' is not of arithmetic type, it is a
Vector3 *
What is it that I am doing wrong here?
struct Vector3
{
float x, y, z;
float magnitude()
{
return sqrt(squareMagnitude());
}
float squareMagnitude()
{
return x*x + y*y + z*z;
}
void scalarMultiply(float scalar)
{
x *= scalar;
y *= scalar;
z *= scalar;
}
void opMulAssign(float scalar)
{
scalarMultiply(scalar);
}
void normalise()
{
float m = magnitude();
if (m) {
this *= 1 / m; // Error
}
}
}
Regards,
Jason
Mar 02 2008
"Spacen Jasset" <spacen yahoo.co.uk> wrote in message news:fqfi8l$haj$1 digitalmars.com... Mar 02 2008
Jarrett Billingsley wrote:"Spacen Jasset" <spacen yahoo.co.uk> wrote in message news:fqfi8l$haj$1 digitalmars.com... Mar 03 2008
|