From your replies to comments in the question it seems that you have an implicit conversion from double
to A
in your class. something like:
class A
{
// ...
public:
A(double);
// ...
};
In this case you can simply define a free function for each operator of the form:
A operator*( const A&, const A& );
and it will be used if either side is an A
object and the other side is implicitly convertible to an A
. For this reason it is often preferable to make symmetric binary operators free functions.
Frequently it can be easier to implement binary *
in terms of the assignment version *=
. In this case I would make the assignment version a member function and define *
as something like:
A operator*( const A& l, const A& r )
{
A result(l);
result += r;
return result;
}
Otherwise as operator*
is plainly part of your class interface I would have no problem with making it a friend
if required.