#include<iostream>using namespace std;class CComplex{public:CComplex(double,double);CComplex(CComplex &c);CComplex add(CComplex &x);void print();private:double real;double image;};CComplex::CComplex(double r=0.0,double i=0.0){real=r;image=i;cout<<"调用两个参数的构造函数"<<endl;}CComplex::CComplex(CComplex &c){real=c.real;image=c.image;cout<<"调用拷贝构造函数"<<endl;}void CComplex::print(){cout<<"("<<real<<","<<image<<")"<<endl;}void f(CComplex n){cout<<"n=";n.print();}CComplex CComplex::add(CComplex &x) (这一句 不懂为何 类名 类名::对象){CComplex y(real+x.real,image+x.image);return y;}int main(){CComplex a(3.0,4.0),b(5.6,7.9);CComplex c(a);cout<<"a=";a.print();cout<<"c=";c.print();f(b);c=a.add(b);c.print();system("pause");}
4 回答
weixin_慕斯卡5464189
TA贡献1条经验 获得超0个赞
CComplex CComplex::add(CComplex &x) (这一句 不懂为何 类名 类名::对象)
前面的CComplex 应该表示的是要返回的类型是CComplex 类型
第二个CComplex 应该才是表示作用域
不知道理解的对不对
- 4 回答
- 0 关注
- 1453 浏览
添加回答
举报
0/150
提交
取消