Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

overloaded operator depends on order 2

Status
Not open for further replies.

liondari

Technical User
Oct 4, 2004
7
GR
Hello everybody,

I use the following definition in a class VecR for vectors:

VecR operator*(const double);

VecR VecR::eek:perator*(const double a)
{
VecR mV(x*a,y*a,z*a);
return (mV);
}

in order to multiply a vector (VecR) and a scalar (double).
Now, say 'A' is a vector and 'fac' is a scalar value.
In the program only 'A * fac' is accepted:
error: no match for 'operator*' in 'fac * A'

Is there a method to create an overloaded operator which
represents both left and right multiplication?

Kind regards
V.K.
 
Of course, add (define) global operator function
Code:
VecR operator *(double,const VecR&)
{
   ...
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top