假定AA为一个类,a为该类私有的数据成员,GetValue( )为该类公有函数成员,它返回a的值,x为该类的一个对象,则访问x对象中数据成员a的格式为( )。
A. x.a
B. x.a()
C. GetValue()
D. x.GetValue( )
查看答案
在程序代码:A::A(int a, int *b) { this->x = a; this->y = b; }中,this的类型是( )
A. int
B. int *
C. A
D. *A
#include using namespace std;class Complex{public:Complex( ){real=0;imag=0;}Complex(double r, double i){real=r;imag=i;}Complex add(Complex c2) ;private:double real; //实部double imag; //虚部};Complex Complex:: add(Complex c2){ Complex temp;temp.real=this->real+c2.real;temp.imag=this->imag+c2.imag;return temp;}int main(){ Complex c1(3,4),c2(5, -10);Complex c3;____________________________//c3为c1与c2的和。return 0;}
class Complex{public:Complex( ){real=0;imag=0;}Complex(double r, double i){real=r;imag=i;}Complex operator+ (Complex c2);private:double real; //实部double imag; //虚部};Complex Complex::operator+ (Complex c2){ Complex temp;temp.real=this->real+c2.real;temp.imag=this->imag+c2.imag;return temp;}int main(){ Complex c1(3,4),c2(5, -10);Complex c3;——————————//c3是c1与c2的和return 0;};请回答:所填写语句中两个操作数通过对象给出的是(),通过参数给出的是()。
class Complex{public:Complex( ){real=0;imag=0;}Complex(double r, double i){real=r;imag=i;}friend Complex operator+= (Complex &, Complex &);private:double real; //实部double imag; //虚部};———————————————————//函数头{c1.real+=c2.real;c1.imag+=c2.imag++;return c1;}