class dkr
{
// 三维坐标
public int x,y,z; // 构造函数
public dkr(int vx,int vy,int vz)
{
x=vx;
y=vy;
z=vz; } // 重载+,用于实现两个笛卡儿坐标的相加 public static dkr operator+=(dkr d1)
{
this.x=this.x+d1.x;
this.y=this.y+d1.y;
this.z=this.z+d1.z; return this;
}}
class test
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
// dkr d1=new dkr(1,2,3),d2=new dkr(4,5,6);
d1.operator+(d2);
Console.WriteLine(d1.x);
Console.WriteLine(d1.y);
Console.WriteLine(d1.z);
}
{
// 三维坐标
public int x,y,z; // 构造函数
public dkr(int vx,int vy,int vz)
{
x=vx;
y=vy;
z=vz; } // 重载+,用于实现两个笛卡儿坐标的相加 public static dkr operator+=(dkr d1)
{
this.x=this.x+d1.x;
this.y=this.y+d1.y;
this.z=this.z+d1.z; return this;
}}
class test
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
// dkr d1=new dkr(1,2,3),d2=new dkr(4,5,6);
d1.operator+(d2);
Console.WriteLine(d1.x);
Console.WriteLine(d1.y);
Console.WriteLine(d1.z);
}
你重载的是+=//d1.operator+(d2);
d1 += d2;MSND关于C#的运算符重载应该讲的比较详细,楼主去看帮助先
应该这样写
dkr d3;
d3=d1+d2;
差不多了,呵呵
d1.operator+(d2);要改为
d1=d1+d2;
{
//....
}