[原创]非托管类中的运算符重载
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
using namespace std;
class Complex
{
public:
int real;
int imaginary;
Complex( )
{
real=0;
imaginary=0;
}
Complex(int a,int b)
{
real=a;
imaginary=b;
}
Complex operator+(Complex A)
{
real=real+A.real;
imaginary=imaginary+A.imaginary;
return Complex(real,imaginary);
}
void ShowComplex( )
{
cout<<"the real part is:"<<real<<endl;
cout<<"the imaginary part is:"<<imaginary<<endl;
}
};
int _tmain()
{
Complex A(2,3),B(4,5),C;
C=A+B;
C.ShowComplex( );
return 0;
}