0

I am trying to overload *

class Vector3
{
public:
  geom_Vector3 operator * (double d);//overload * from the left
};

geom_Vector3 operator * (double d, geom_Vector3 &V); //overload * from the right

The problem is this works

geom_Vector3 V(1,2,3);
cout << -1 * V << endl;

but this doesn't

cout << -1 * geom_Vector3(1,2,3) << endl;

Do I have to also have a * for const Vector3's somehow?

Thanks!
Dave

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Radical Edward
0

The binary * operator usually doesn't modify the state of the object anyway. It should always take a const reference:

geom_Vector3 operator * (double d, const geom_Vector3 &V);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.