So I have a matrix class (of type Derived) based on CRTP that takes two template parameters template<class T, class Derived>, and need to overload the binary operators +, - and * for a matrix multiplied by a scalar (of class T). For the * operator it will for instance be
template <class T, class Derived>
Derived operator*(const Derived &other, const T scalar)
{
Derived result = other;
for (size_t i = 0 ; i < other.get_rows(); i++)
{
for (size_t j = 0; j < other.get_cols(); j++)
{
result(i, j) *= scalar;
}
}
return result;
}
template <class T, class Derived>
Derived operator*(const T scalar, const Derived &other) { return other * scalar; }
And then for example with a * A, where a is a double scalar and A a matrix object (dynamic), the compiler will not understand which operator to use, regardless of the class types, because of ambiguity in which template (T or Derived) to use.
Anyone have a solution here? Do I need to overload for specific template parameters such as double, int etc..?
Ts can you multiply to a matrix object? What combination of types are allowed which arent? - 463035818_is_not_a_number