填空题
在下面的类定义中,this指针的用途是
【11】
。
#include <iostream. h>
class Sample
int x,y;
public:
Sample(int i,int j)x=i;y=j;
void asstgn(Sample sa):
;
void Sample: :assign(Sample p)
if (this! =&p)
x=p.x;
y=p.y;
【参考答案】
防止对类对象自己给自己赋值
点击查看答案&解析
<上一题
目录
下一题>
热门
试题
填空题
下列程序的运行结果为 【9】 。 #include<iostream, h> void main( ) int i; for(i=1; i<6;i++)if(i==3) break: com<< i= <<i<<end1;
点击查看答案&解析
填空题
下列程序中的this指针的作用是 【13】 。 #include <iostream. h> class Sample int n; static int st; public, Sample() Sample(int m) n=m; st=m+10; void Change(int k) st=st+k; void AddValue(int m) Sample s, s. n=n+m; *this=s; void disp( ) cout<< n= <<n<< ;st= <<st<<end1; ; int Sample: :st=0 void main() Sample s1(10),s2(10) s1. disp() s1. AddValue(5), s2. Change(100); s1. disp(); s2. disp()
点击查看答案&解析
相关试题
下列程序的运行结果是 【15】 。 #in...
下列程序的运行结果为 【14】 。 #in...