#include <iostream>using namespace std;class CComplex{public: CComplex() { real = 0; imag = 0; } CComplex(int x,int y)// 1 { real = x; imag = y; } int real; int imag; CComplex operator + (CComplex obj1) { CComplex obj2(real + obj1.real, imag + obj1.imag);// 2 return obj2; }};int main(){ CComplex obj1(100,30); // 3 CComplex obj2(20, 30); CComplex obj; obj = obj1+obj2; cout << obj.real <<endl; cout << obj.imag << endl;}
1 回答
已采纳
习惯受伤
TA贡献885条经验 获得超1144个赞
1,CComplex(int x,int y)的意思是CComplex的构造函数啊。
2,CComplex obj2(real + obj1.real, imag + obj1.imag)的意思是初始化一个名为obj2的CComplex对象,并调用其构造函数赋值。
3,CComplex obj1(100,30);同2
- 1 回答
- 0 关注
- 1258 浏览
添加回答
举报
0/150
提交
取消