程序执行的时候出现错误了
大家帮着改下 谢谢了啊
main.cpp中的文件
#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include"stack.h"
const int MaxLength=100;
void PrintMatchedPairs(char *expr)
{
Stack<int>s(MaxLength);
int j,length=strlen(expr);
for(int i=1;i<=length;i++)
{
if(expr[i-1]=='(')s.add(i);
else if(expr[i-1]==')')
try
{
s.Delete(j);
cout<<j<<" "<<i<<endl;
}
catch()
{
cout<<"no match for right parenthesis"<<"at"<<i<<endl;
}
}
while(!s.isempty())
{
s.Delete(j);
cout<<"no match for left parenthesis at"<<j<<endl;
}
}
void main(void)
{
char expr[MaxLength];
cout<<"type an expression of length at most"<<MaxLength<<endl;
cin.getline(expr,MaxLength);
cout<<"the pairs of matching parenthesis in"<<endl;
puts(expr);
cout<<"are"<<endl;
PrintMatchedPairs(expr);
}
Stack.h中的文件
template<class T>
class Stack
{
public:
Stack(int MaxStackSize=10);
~Stack(){Delete[]stack;}
bool isempty()const{return top==-1;}
bool isfull()const{return top==maxtop;}
T Top()const;
Stack<T>& add(const T& x);
Stack<T>& Delete(T& x);
private:
int top;
int maxtop;
T *stack;
};
template<class T>
Stack<T>::Stack(int MaxStackSize)
{
maxtop=MaxStackSize-1;
stack=new T[MaxStackSize];
top=-1;
}
template<class T>
T Stack<T>::Top()const
{
if(isempty())return false;
else return stack[top];
}
template<class T>
Stack<T>& Stack<T>::add(const T& x)
{
if(isfull())throw nomem();
stack[++top]=x;
return *this;
}
template<class T>
Stack<T>& Stack<T>::Delete(T& x)
{
if(isempty())return false;
x=stack[top--];
return *this;
}
--------------------Configuration: main - Win32 Debug--------------------
Compiling...
main.cpp
D:\Program Files\Microsoft Visual Studio\MyProjects\kuo\main.cpp(19) : error C2310: catch handlers must specify one type
D:\Program Files\Microsoft Visual Studio\MyProjects\kuo\main.cpp(23) : error C2317: 'try' block starting on line '15' has no catch handlers
执行 cl.exe 时出错.
main.exe - 1 error(s), 0 warning(s)