重载运算符+

#include 
using namespace std;

class Complex
{
public:
	Complex(){real=0;image=0;}
	Complex(double r,double i){real=r;image=i;}
	Complex operator+(Complex &c2);
	void display();

private:
	double real;
	double image;
};

Complex Complex::operator+(Complex &c2)
{
	Complex c;
	c.real=real+c2.real;//real为c1对象中的real
	c.image=image+c2.image;
	return c;
}

void Complex::display()
{
	cout<<"("<

你可能感兴趣的:(重载运算符,编程基础)