高手帮我看看模板类下重载加法的问题
#include<iostream>using namespace std;
template<typename T>
class Vec3
{
private:
T x;
T y;
T z;
public:
T GetX()const{return x;}
T GetY()const{return y;}
T GetZ()const{return z;}
Vec3(T a,T b,T c):x(a),y(b),z(c){}
friend ostream& operator<<(ostream& out,Vec3<T>& r)
{
out<<"("r.GetX()<<","<<GetY()<<","<<GetZ()<<")";
return out;
}
friend Vec3 operator+(float& t,Vec3<T>& r)
{
return Vec3(t+r.GetX(),t+r.GetY(),t+r.GetZ());
}
};
void main()
{
Vec3<double>a(1,2,3);
Vec3<double>b(3,4,5);
cout<<a+b;
}
第一次编这个,高手 帮忙看看加法重载那边有什么问题,谢谢了