Originally Posted by
Ocifer
You are right that two arbitary matrices don't necessarily commute, but that's not quite what I meant.
As a matter of fact, you asked for that. Asking for the same function to be called for 2.0*a_vector and for a_vector*3.0 means you want them to commute in this particular case.
Originally Posted by
Ocifer
Does anyone have a more elegant way to achieve what I've done?
You still need to provide both operators, but can implement one in terms of the other.
For example;
Code:
Vect operator*(Vect the_vect, float scalar)
{
return operator*(scalar, the_vect);
}
Note that, generally speaking, it is often better to pass class arguments by const reference than by value. As in
Code:
Vect operator*(const Vect &the_vect, float scalar)
{
return operator*(scalar, the_vect);
}
The benefits of this include avoiding the overhead of creating a temporary copy of vectors passed by the caller.