表达式计算器错误 CXX0030 !
#include <iostream>using namespace std;
class Array
{
public:
Array ( int length = 10 );
~Array ( );
int operator [] ( int i );
private :
int *element;
int len;
};
Array::Array(int length)
{
len=length;
}
Array::~Array()
{
delete[] element;
}
int Array::operator[](int i)
{
if(i<0||i>=len)
{
cerr<<"invalid i"<<i<<",range is 0 to "<<len-1<<endl;
exit(1);
}
}
class stack : public Array
{
public:
stack();
stack(int t,int l);
bool empty();
int peek();
void push(int value);
int pop();
int getSize();
void printStack();
bool contains(int e);
private:
int top;
int *num;
};
stack::stack()
{
top=-1;
}
stack::stack(int t,int length):Array(length)
{
top=t;
}
bool stack::empty()
{
if(top==-1)
return true;
return false;
}
int stack::peek()
{
return num[top];
}
void stack::push(int value)
{
num[++top]=value;
}
int stack::pop()
{
return num[top--];
}
int stack::getSize()
{
return top+1;
}
void stack::printStack()
{
int i;
for(i=0;i<=top;i++)
{
cout<<num[i]<<" ";
}
cout<<endl;
}
bool stack::contains(int e)
{
int i;
for(i=0;i<=top;i++)
{
if(e==num[i])
{
return true;
}
}
return false;
}
int main()
{
int size,item,number;
cin>>size;
stack stack(size-1,size);
cout<<stack.getSize()<<endl;
for(int i=1;i<=size;i++)
{
cin>>number;
stack.push(number);
}
cout<<stack.peek()<<endl;
cout<<stack.getSize()<<endl;
cout<<stack.pop()<<endl;
cout<<stack.getSize()<<endl;
cout<<stack.empty()<<endl;
for(int i=0;i<stack.getSize()-1;i++)
cout<<stack.pop()<<" ";
cout<<endl;
cout<<stack.empty()<<endl;
cin>>item;
cout<<stack.contains(item)<<endl;
return (0);
}
一直找不到解决方法,不知道怎么修改,求帮助!