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

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);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.