求助大神们~~报错看不懂= =

zhengsy1994 2012-08-31 05:03:48
#include <iostream>
void MyFunc(void);
class Expt
{
public:
Expt(){};
~Expt(){};
const char *ShowReason() const
{return "Expt类异常";}
};
class Demo{
public:
Demo();
~Demo();
};
Demo::Demo()
{cout<<"构造Demo。"<<endl;
}
Demo::~Demo()
{cout<<"析构 Demo。"<<endl;
}
void MyFunc(){
Demo D;
throw Expt;
}
int main ()
{
cout<<"在main函数中。"<<endl;
try
{cout<<"在try块中,调用MyFunc()。"<<endl;
MyFunc();
}
catch (Expt E)
{
cout<<"在catch异常处理程序中。"<<endl;
cout<<"捕获到Expt类型异常:";
cout<<E.ShowReason()<<endl;
}
catch(char*str)
{
cout<<"捕获到其他异常:"<<str<<endl;
}
cout<<"回到main函数。从这里恢复运行。"<<endl;
return 0;
}




报错在这里~!
D:\Program Files\Desktop\新建文件夹\ou.cpp(17) : error C2065: 'cout' : undeclared identifier
D:\Program Files\Desktop\新建文件夹\ou.cpp(17) : error C2297: '<<' : illegal, right operand has type 'char [11]'
D:\Program Files\Desktop\新建文件夹\ou.cpp(17) : error C2065: 'endl' : undeclared identifier
D:\Program Files\Desktop\新建文件夹\ou.cpp(20) : error C2297: '<<' : illegal, right operand has type 'char [12]'
D:\Program Files\Desktop\新建文件夹\ou.cpp(24) : error C2275: 'Expt' : illegal use of this type as an expression
D:\Program Files\Desktop\新建文件夹\ou.cpp(4) : see declaration of 'Expt'
D:\Program Files\Desktop\新建文件夹\ou.cpp(28) : error C2297: '<<' : illegal, right operand has type 'char [15]'
D:\Program Files\Desktop\新建文件夹\ou.cpp(30) : error C2297: '<<' : illegal, right operand has type 'char [26]'
D:\Program Files\Desktop\新建文件夹\ou.cpp(35) : error C2297: '<<' : illegal, right operand has type 'char [24]'
D:\Program Files\Desktop\新建文件夹\ou.cpp(36) : error C2297: '<<' : illegal, right operand has type 'char [21]'
D:\Program Files\Desktop\新建文件夹\ou.cpp(37) : error C2297: '<<' : illegal, right operand has type 'const char *'
D:\Program Files\Desktop\新建文件夹\ou.cpp(41) : error C2297: '<<' : illegal, right operand has type 'char [16]'
D:\Program Files\Desktop\新建文件夹\ou.cpp(43) : error C2297: '<<' : illegal, right operand has type 'char [31]'
...全文
103 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhaoZero41 2012-08-31
  • 打赏
  • 举报
回复
throw Expt();


throw之后是接表达式的,表达式的类型决定了会被哪个catch捕获。
zhengsy1994 2012-08-31
  • 打赏
  • 举报
回复
确实= =
那个。。不过还是又错~~

D:\Program Files\Desktop\新建文件夹\ou.cpp(25) : error C2275: 'Expt' : illegal use of this type as an expression
D:\Program Files\Desktop\新建文件夹\ou.cpp(5) : see declaration of 'Expt'
[Quote=引用 1 楼 的回复:]

using namespace std;
[/Quote]
zjs100901 2012-08-31
  • 打赏
  • 举报
回复
using namespace std;

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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