Hey, I've created a templated Vector class and I want to be able to overload addition/multiplication operators etc. But I'm having a problem when combining different datatypes, for example Vector<double> * Vector<int>. The best solution I could think of was the following:
This works for the usual case of having a T=double and U=int, or T=int and U=double. But it's not as general as I'd like. Is there a better solution to this (i'd assume) common problem?Code:template <typename T, typename U> inline friend double operator*(const Vector<T>& lhs, const Vector<U>& rhs) { return (lhs[0]*rhs[0] + lhs[1]*rhs[1]); }



LinkBack URL
About LinkBacks



