|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<iostream>
using namespace std;
class Complex
{
private:
double real, image;
public:
Complex() { real = 0; image = 0; }
Complex(double r) { real = r; image = 0; } //转换构造函数
Complex(double r, double i) { real = r; image = i; } //初始化构造函数
friend Complex operator+(Complex c1, Complex c2); //为什么在c1,c2前加&就报错呢?想不明白5555
};
Complex operator+(Complex c1, Complex c2)
{
Complex c;
c.real = c1.real + c2.real;
c.image = c1.image + c2.image;
return c;
}
int main()
{
Complex c1(-1, 2), c2(-1, 1), c3;
double d = 2.1;
c3 = c1 + d;
}
请帮忙看看友员的那行代码,球球了
|
|