Will Lafreniere Will Lafreniere - 1 year ago 104
C++ Question

Overloaded operator undefined

I'm following a book called: Game Physics Engine Development. In the book, the author create a custom type(real) to allow him to switch easily between float an double without changing the entire program. He then overload the *= operator to allow a vector dot product.

typedef float real;
#define RealSqrt sqrt
#define RealPow powf;

EDIT: And here's the vector class.

class Vector3D
real x;
real y;
real z;

void operator *=(const real value)
x *= value;
y *= value;
z *= value;

My problem is that when I use the macro(RealPow) that I defined with my *= operator, Visual Studio highlight an error telling me that the operator *= is undefined for such parameters. (velocity is a vector)

velocity *= RealPow(damping, duration);

But what I don't understand is than when I write it directly with powf, there's no problem.

velocity *= powf(damping, duration);

EDIT: The error that it gives me is: No operator "*=" matches these operands: Vector3D *= float_cdecl(float _x, float _y)

Am I doing something wrong?

Answer Source

Your define line

#define RealPow powf;

should not have an extra semicolon at the end.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download