构造函数的try如何用不了
构造函数的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 ");;
};
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 ");;
};