Hello everyone,
New poster here and semi-experienced with c++.
I have a quick question; Is it possible to simplify overridden operators for custom classes?
This is the case:
For school we have to make a game with Vector Motion, currently in 2D. ANd in most programs I've worked with (XNA C#, Unity) you can use '+', '-' etc. operands.
I managed to get them working in C++ like so:
IN MY VECTOR2.H:
void operator += (Vector2* vector) {x+=vector->x; y+=vector->y;}
IN MY GAME.CPP:
player.transform.velocity = new Vector2(player.xVelocity, player.yVelocity);
player.transform.velocity->operator+=(player.transform.velocity);
But I just want to be able to do something like Vector2+=Vector2 instead of Vector2(function_call)(function_parameter).
Is this possible?
I have also looked at
http://www.cplusplus.com/doc/tutorial/classes2/, but when I use this method I'm getting an error about arithmetics.
Regards,
Zubaja