I encountered a problem when I'm implementing the vector-op-scalar operators for my short-vector class. And the code lists as follows:
template<class T>
class Vec3
{
Vec3& operator*=( const T& rhs );
};
template<class T>
Vec3<T> operator*( const Vec3<T>& lhs, const T& rhs );
Vec3<float> a;
a*=3; // right
a*3; // wrong
Well, I'm really surprised that for the operator*=, as I expected, the constant integer 3 can be automatically convert to float, but for the operator*, it couldn't, and resulting a compile error lists below:
error C2782: 'Vec3 operator *(const Vec3 &,T)' : template parameter 'T' is ambiguous
main.cpp(162) : see declaration of 'operator *' could be 'int' or 'float'
I'm really confused about this and have no idea about why it happens.