关于++ 运算符重载的问题
using System;using System.Collections.Generic;
using System.Text;
namespace Test11_38
{
class Distance
{
private double Meter = 0;
public Distance(double M)
{
this.Meter = M;
}
public double getmeter{
get
{
return Meter;
}
set
{
Meter =value;
}
}
public static Distance operator + (Distance M1, Distance M2)
{
return new Distance(M1.Meter + M2.Meter);
}
public static Distance operator * (Distance M1, Distance M2)
{
return new Distance(M1.Meter * M2.Meter);
}
/** public static Distance operator ++(Distance M1)
{
return new Distance(M1.Meter++);
}
**/
public static Distance operator ++(Distance M)
{
M.getmeter++;
return M;
}
}
class Surface
{
private double Cube;
public Surface(double C)
{
this.Cube = C;
}
public double GetCube
{
get
{
return Cube;
}
set
{
Cube = value;
}
}
public static Surface operator + (Surface C1, Surface C2)
{
return new Surface(C1.Cube + C2.Cube);
}
public static Surface operator * (Surface C1, Distance M1)
{
return new Surface(C1.Cube * M1.getmeter);
}
public static Surface operator *(Distance M1, Surface C1)
{
return C1 * M1;
}
}
class Program
{
static void Main(string[] args)
{
Distance M1, M2;
M1 = new Distance(10.0);
M2 = new Distance(70.0);
Surface C1;
C1 = new Surface(8.0);
Console.Write("The result is " + (M1.getmeter + M2.getmeter));
Console.Write("\n");
Console.Write("Another result is" + C1.GetCube * M1.getmeter);
Console.Write("\n");
Distance M3 = M1++;
M2 = ++M3;
Console.Write("after ++ The result is {0},{1},{2}",M1.getmeter,M2.getmeter,M3.getmeter);
}
}
}
结果为12 12 12 为什么重载以后不能得到是11 13 13呢 或者其它结果 希望大家解释下具体重载调用过程