//其本质就是运算符重载 operator+
#include "stdafx.h"
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
class complex
{
public:
float real;
float imag;
public:
complex() //默认构造函数
{
real=0;
imag=0;
}
//双参数构造函数
complex(float re,float im)
{
real=re;
imag=im;
}
//运算符+重载
complex operator+(const complex & c)const
{
complex v;
v.real=real+c.real;
v.imag=imag+c.imag;
return v;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
//--------------------------------------------------------------
//自定义类型运算
complex c1(1.0,2.0);
complex c2(3.0,4.0);
complex c3=c1+c2;
getchar();
return 0;
}