65,211
社区成员
发帖
与我相关
我的任务
分享
class Expt
{
public:
Expt( )
{
i=0;
cout <<"Expt()" <<endl;
}
Expt(Expt &o)
{
i=1;
cout <<"copy Expt()..." <<endl;
}
/*
*/
~Expt()
{
cout <<"~Expt()" << " - " <<i <<endl;
}
Expt & operator=(Expt&one)
{
cout << "operator ="<<endl;
}
const char *ShowReason() const
{
return "Expt...";
}
private:
int i;
};
void MyFunc()
{
cout <<"MyFunc" <<endl;
throw Expt();
}
int main()
{
try
{
cout <<"Enter try..." <<endl;
MyFunc();
}
catch ( Expt &E )
{
cout <<E.ShowReason() <<endl;
}
return 0;
}
catch( Expt& E )
如果是catch( Expt E ) ,会调用复制构造函数。产生的一个临时对象析构造成的!