i want to use std::enable_if<> to avoid ambigous overloaded operator*(T,U)
(or redefinitions) from MyClass*otherT
vs otherT*MyClass
vs MyClassT*MyClassT
lets say MyClass
declaration is:
template <typename T> class MyClassT { ... }
then on global scope :
template <typename T, typename U>
MyClassT<T> operator*(const MyClassT<T>& t, const MyClassT<U>& u)
{
//...
}
template <typename T, typename U, std::enable_if_t<!std::is_same_v<MyClassT<T>, U>> = true >
MyClassT<T> operator*(const MyClassT<T>& t, const U& u)
{
//...
}
template <typename T, typename U, std::enable_if_t<!std::is_same_v<MyClassT<U>, T>> = true >
MyClassT<U> operator*(const T& t, const MyClassT<U>& u)
{
//...
}
but the code of
MyClassT<double> a;
double b;
MyClassT<double> c = a * b;
still can’t find the overloaded operator for it, need help whats is wrong ?
1