谁可以帮我解释一下 这是什么意思啊 我是初学者 不是很懂。
#include "stdafx.h"#include<iostream>
using namespace std;
class complex {
public:
complex() { real = 0, image = 0; }
complex(double r, double i) { real = r; image = i; }
friend complex add(complex &c1, complex &c2);
void display();
private:
double real;
double image;
};
complex add(complex &c1, complex &c2) {
complex c3;
c3.real = c1.real + c2.real;
c3.image = c1.image + c2.image;
return c3;
}
void complex::display() {
cout << real << "+" << image << "i" << endl;
}
int main() {
complex c1(3, 4), c2(6, 8), c3;
c3 = add(c1, c2);
cout << "c1=", c1.display();
cout << "c2=", c2.display();
cout << "c3=", c3.display();
return 0;
}