I have classes:
class IntegerVector:
{
IntegerVector operator * (const int scalar) const;
};
class RealVector:
{
RealVector(const IntegerVector &other);
RealVector operator * (const double scalar) const;
};
How can I force the expression: integer_vector*1.5 to be equivalent to RealVector(integer_vector)*1.5 rather than integer_vector*int(1.5) as it is now?
EDIT
BTW, there are lots of these operators, so defining RealVector IntegerVector::operator * (const double scalar) const is not very satisfactory.
In C++11, you could leverage the built-in type promotion like this:
If you need this without decltype, you can probably implement the type promotion result as a meta-function too. I suppose an operator implementation would look something like this: