I come from a world of c# were doing something like this is allowed. When I try it in c++ I get no compiler errors but I am not convinced it is actually working.
So to more experienced people are you allowed to do something like this:
Entity->SetPosition(Vector2(200, 400));
As In Vector2 is a class and the parameter for set position requires a vector? Is this allowed or do I need to pre-initialize the variable like so:
Vector2 aVector(200, 400);
Entity->SetPosition(aVector);
Thanks
David
is fine (and preferable) if you’ve defined
SetPositionas one of the following:that is,
SetPositionaccepts the argument asconstreference, Or simply as value.This wouldn’t work though:
—
In C++11, you could just write this (provided you have implemented
Vector2to enable this behavior):Thanks to @Simon for pointing this out.