不知道是不是一个类型问题
这是一个堆栈的顺序表示里实现的一些基本运算,编译总是出错误,我就发个主函数,错误我放在下面了,大家帮我看看了
就是那个异常处理那里出问题了,按道理说是catch可以捕获的类型的,但不知道怎么使用,不知道是不是要包含什么头文件
我不知道要包含什么头文件,算了,大家看发上来的那个错误就知道了
/main.cpp
#include <iostream>
#include "Stack.h"
using namespace std;
void main()
{
try
{
SeqStack<double> dstk(2); //构造一个容量为2的双精度数栈
dstk.Push(3.7);
dstk.Push(8.8); //向栈中依次加入3.7和8.8
cout<<dstk; //输出栈中元素
dstk.Pop();
if(dstk.IsEmpty()) //判定栈是否为空
cout<<"Is empty!"<<endl;
else
cout<<"Is not empty!"<<endl;
dstk.Pop(); //两次删除运算,将产生下溢异常
dstk.Pop();
}
catch(ResultCode err)
{
switch(err) //根据异常类别,处理异常
{
case Overflow:
cout<<"Overflow!"<<endl;
break;
case Underflow:
cout<<"Underflow!"<<endl;
break;
}
}
}
错误:
--------------------Configuration: 堆栈的顺序表示练习 - Win32 Debug--------------------
Compiling...
main.cpp
E:\数据结构\第三章\堆栈的顺序表示练习\main.cpp(21) : error C2061: syntax error : identifier 'ResultCode'
E:\数据结构\第三章\堆栈的顺序表示练习\main.cpp(21) : error C2310: catch handlers must specify one type
E:\数据结构\第三章\堆栈的顺序表示练习\main.cpp(23) : error C2065: 'err' : undeclared identifier
E:\数据结构\第三章\堆栈的顺序表示练习\main.cpp(25) : error C2065: 'Overflow' : undeclared identifier
E:\数据结构\第三章\堆栈的顺序表示练习\main.cpp(25) : error C2051: case expression not constant
E:\数据结构\第三章\堆栈的顺序表示练习\main.cpp(28) : error C2065: 'Underflow' : undeclared identifier
E:\数据结构\第三章\堆栈的顺序表示练习\main.cpp(28) : error C2051: case expression not constant
E:\数据结构\第三章\堆栈的顺序表示练习\main.cpp(31) : warning C4060: switch statement contains no 'case' or 'default' labels
E:\数据结构\第三章\堆栈的顺序表示练习\main.cpp(33) : error C2317: 'try' block starting on line '8' has no catch handlers
执行 cl.exe 时出错.