Java - class declared operators
Hello. I would like to make operators for a 2D vector class. I know how to do this easily in C++, but how would I add these operators in Java?
Thanks,
--SgtSparky
Unfortunately, you cannot overload operators in Java.
You've got to do it all through function calls, e.g.Damn you Java...
You've got to do it all through function calls, e.g.
Vec2d a = new Vec2d;Vec2d b = new Vec2d( 0, 1 );Vec2d c = new Vec2d( 3, 0 );a.AssignSum( b, c );//a now equals (3,1)
Java doesn't support operator overloading. You just have to write methods that will do the operations..
for instance:
Vector vec1 = new Vector (1.0f, 2.0f, 3.0f);
Vector vec2 = new Vector (5.0f, 5.0f, 5.0f);
Vector vec3 = vec1.dotProduct (vec2);
or similar..
for instance:
Vector vec1 = new Vector (1.0f, 2.0f, 3.0f);
Vector vec2 = new Vector (5.0f, 5.0f, 5.0f);
Vector vec3 = vec1.dotProduct (vec2);
or similar..
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement