猿问

请问1,2,3处的CComplex分别有什么作用

#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;

}


不凡的蚂蚁
浏览 1259回答 1
1回答

习惯受伤

1,CComplex(int x,int y)的意思是CComplex的构造函数啊。 2,CComplex obj2(real + obj1.real, imag + obj1.imag)的意思是初始化一个名为obj2的CComplex对象,并调用其构造函数赋值。 3,CComplex obj1(100,30);同2
随时随地看视频慕课网APP
我要回答