首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

构造函数的try如何用不了

2012-03-31 
构造函数的try怎么用不了啊classBase{intipublic:classBaseException{}Base(intI):i(I){throwBaseExcept

构造函数的try怎么用不了啊
class   Base
{
int   i;
public:
class   BaseException   {};
Base(int   I):i(I){throw   BaseException();}  
};
class   Derived:public   Base
{
public:
class   DeriveException
{
const   char*   msg;
public:
DeriveException(const   char*   pmsg):msg(pmsg){}
const   char*   what(){return   msg;}
};

Derived(int   I)   try   :Base(I)
{
cout   < < "This   won 't   print "   < <endl;
}
catch   (BaseException&   t)  
{
throw   DeriveException( "Base   subject   throw ");;
};
};
编译不过,提示好多错误,书上都是这么写的啊!

D:\project\Test2\Test2.cpp(162)   :   error   C2143:   syntax   error   :   missing   '; '   before   'try '
D:\project\Test2\Test2.cpp(162)   :   error   C2059:   syntax   error   :   'try '
D:\project\Test2\Test2.cpp(162)   :   error   C2334:   unexpected   token(s)   preceding   ': ';   skipping   apparent   function   body
D:\project\Test2\Test2.cpp(166)   :   error   C2059:   syntax   error   :   'catch '
D:\project\Test2\Test2.cpp(167)   :   error   C2334:   unexpected   token(s)   preceding   '{ ';   skipping   apparent   function   body

[解决办法]
VC6吧?扔了,换devcpp、VC2005
[解决办法]
http://blog.csdn.net/armman/archive/2007/03/15/1530833.aspx
[解决办法]
Derived(int I):Base(I)
{
try
{
cout < < "This won 't print " < <endl;
}
catch (BaseException& t)
{
throw DeriveException( "Base subject throw ");
}
}
=======================================================================
Derived(int I) try :Base(I)
{
cout < < "This won 't print " < <endl;
}
catch (BaseException& t)
{
throw DeriveException( "Base subject throw ");;
};

热点排行
Bad Request.