【发布时间】:2014-11-27 02:06:25
【问题描述】:
http://codepaste.net/i87t39 我得到的错误是“二元运算符的参数之一必须是包含类型”
public class Vector3D<T>
{
public T x;
public T y;
public T z;
public Vector3D()
{
}
public Vector3D(T a, T b, T c)
{
x = a; y = b; z = c;
}
/*public Vector3D(double a, double b, double c)
{
x = a; y = b; z = c;
}*/
public override string ToString()
{
//return base.ToString();
return String.Format("({0} {1} {2})", x , y , z);
}
public Vector3D<double> operator+( Vector3D<double> right)
{
Vector3D<double> vd = new Vector3D<double>() { x = 0, y = 0, z = 0};
vd.x = left.x + right.x;
vd.y = left.y + right.y;
vd.z = left.z + right.z;
return vd;
}
}
【问题讨论】: