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);

}

解决方案 »

  1.   

    //public static dkr operator+=(dkr d1)
    你重载的是+=//d1.operator+(d2);
    d1 += d2;MSND关于C#的运算符重载应该讲的比较详细,楼主去看帮助先
      

  2.   

    我认为它重载的是“+”
    应该这样写
    dkr d3;
    d3=d1+d2;
    差不多了,呵呵
      

  3.   

    除了定义处“+=”换为“+”外 
     d1.operator+(d2);要改为
    d1=d1+d2;
      

  4.   

    public static dkr operator+(dkr d1,dkr d2)
    {
        //....
    }