标题:表达式计算器错误 CXX0030 !
只看楼主
saki1991
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-2-28
 问题点数:0 回复次数:1 
表达式计算器错误 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);
}

一直找不到解决方法,不知道怎么修改,求帮助!
搜索更多相关主题的帖子: class 计算器 private element include 
2011-12-18 22:45
saki1991
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-2-28
得分:0 
=3=求救啊。。。。
2011-12-19 10:18



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-358085-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.685023 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved