帮忙看看错在哪

APIandMFC 2008-11-19 11:00:23

#include<iostream>
using namespace std;
class Base
{
int i;
public:
class BaseExcept{};
Base(int ii):i(ii){throw BaseExcept();}//成员对象初始化时抛出了异常。
};
class Derived:public Base
{
public:
class DerivedExcept
{
const char* msg;
public:
DerivedExcept(const char* message):msg(message){}
const char* what()const{return msg;}
};
Derived(int j)try:Base(j)
{
cout<<"This won't print"<<endl;
}
catch(BaseExcept&)
{
throw DerivedExcept("Base subobject threw");;
}
};
int main()
{
try
{
Derived d(3);
}
catch(Derived::DerivedExcept& d)
{
cout<<d.what()<<endl;
}
return 0;
}


请告诉我你用的是什么编译器 谢谢.
...全文
116 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
就呆在云上 2008-11-20
  • 打赏
  • 举报
回复
vc++ 2008 express,补上
就呆在云上 2008-11-20
  • 打赏
  • 举报
回复
程序没有错误啊,输出:
Base subobject threw

xianyuxiaoqiang 2008-11-20
  • 打赏
  • 举报
回复
帮UP
bfhtian 2008-11-20
  • 打赏
  • 举报
回复
up
太乙 2008-11-19
  • 打赏
  • 举报
回复
lz应该多准备几个编译器!

vc6.0对函数级try catch不支持!
太乙 2008-11-19
  • 打赏
  • 举报
回复
#include<iostream>
using namespace std;
class Base
{
int i;
public:
class BaseExcept{};
Base(int ii):i(ii){throw BaseExcept();}//成员对象初始化时抛出了异常。
};
class Derived:public Base
{
public:
class DerivedExcept
{
const char* msg;
public:
DerivedExcept(const char* message):msg(message){}
const char* what()const{return msg;}
};
Derived(int j)try:Base(j)
{
cout<<"This won't print"<<endl;
}
catch(BaseExcept&)
{
throw DerivedExcept("Base subobject threw");;
}
};
int main()
{
try
{
Derived d(3);
}
catch(Derived::DerivedExcept& d)
{
cout<<d.what()<<endl;
}
system("pause");
return 0;
}





===========================

Base subobject threw
请按任意键继续. . .


dev-c++

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧