I am wondering if there is a way to do this in C ++. Say I have a template vector class:
template <typename T> class vector { public: vector(T a, T b, T c) : x(a), y(b), z(c) {} T x,y,z; };
And then I have a templated addition operator:
template <typename A, typename B> vector<A> operator +(const vector<A> &a, const vector<B> &b) { return vector<A>(a.x+bx, a.y+by, a.z+bz); }
I am curious if this operator can be modified so that the result depends on which of the two types A and B is more accurate, except that it manually specializes in it.
For example:
vector<float> + vector<double> would produce a vector<double>, vector<long double> + vector<float> would produce a vector<long double>
I assume that in C ++ there is no automatic support, but I thought I would ask.
c ++ templates
Sean mcallister
source share