level 12
#include "stdafx.h"
#include<iostream>
using namespace std;
class csample
{char ch1,ch2;
public:friend void set(csample &s,char c1,char c2);
csample (char a,char b){ch1=a;ch2=b;cout<<"csample con"<<endl;}
csample(const csample&rhs){ch1=rhs.ch1;ch2=rhs.ch1;
cout<<"csample copy"<<endl;}
csample &operator=(const csample &rhs){ch1=rhs.ch1;ch2=rhs.ch1;cout<<"csample operator="<<endl; return *this;}
~csample(){cout<<"ch1"<<ch1<<",ch2"<<ch2<<endl;}
};
void set(csample &s,char c1,char c2){s.ch1=c1;s.ch2=c2;}
csample fun(csample obj){set(obj,'7','9');return obj;}
void main( ){csample obj1('7','8');csample obj2=obj1;obj2=fun(obj1);}
2011年04月23日 15点04分
1
level 12
#include "stdafx.h"
这句不要贴上来...
2011年04月23日 15点04分
2
level 12
e 我不懂运行结果怎么来的
有3个位置调了拷贝构造函数,不知为何
2011年04月23日 15点04分
5
level 8
csample obj2=obj1;//这里赋值一次
obj2=fun(obj1);//将对象传进去一次,返回一次,1+1+1=3
2011年04月23日 15点04分
6
level 8
所以建议LZ改一下:
csample &fun(csample &obj){set(obj,'7','9');return obj;}
2011年04月23日 15点04分
7
level 8
这样就剩下一次必不可少的:
csample obj2=obj1;//一次
2011年04月23日 15点04分
8
level 12
csample conc
sample copyc
sample copyc
sample copy
ch17,ch29
csample operator=ch17,ch27ch17,ch27ch17,ch28请按任意键继续. . .
2011年04月23日 16点04分
10
level 8
回复:10楼
没有错。。孩子。。自己悟。。我睡了。。明天2级。。
2011年04月23日 16点04分
11
level 12
额 csample obj2=obj1。分别调用了哪些函数,输出了什么啊。我一直认为它掉了那个重载的等号,但运行结果……
2011年04月24日 00点04分
12
level 1
(=_=LL)在C++贴吧的代码要用什么格式才能读取?
2011年04月24日 02点04分
13