大家帮帮看看这个代码 求运行结果
c++吧
全部回复
仅看楼主
level 12
QQ懒羊羊QQ 楼主

#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
QQ懒羊羊QQ 楼主
e 我不懂运行结果怎么来的
有3个位置调了拷贝构造函数,不知为何
2011年04月23日 15点04分 5
level 12
QQ懒羊羊QQ 楼主
不对,你运行一下 看看拷贝函数的顺寻 有问题
2011年04月23日 15点04分 9
level 12
QQ懒羊羊QQ 楼主
csample conc
sample copyc
sample copyc
sample copy
ch17,ch29
csample operator=ch17,ch27ch17,ch27ch17,ch28请按任意键继续. . .
2011年04月23日 16点04分 10
level 12
QQ懒羊羊QQ 楼主
额 csample obj2=obj1。分别调用了哪些函数,输出了什么啊。我一直认为它掉了那个重载的等号,但运行结果……
2011年04月24日 00点04分 12
1