注册 登录
编程论坛 C++教室

c++编程序中遇到问题,想求解疑

白杨树cy 发布于 2008-11-19 20:01, 896 次点击
我自己编了两个文件自定义一个类功是用数组表示栈,分别是stack.h和stack.cpp这两个文件内容分别是:
stack.h内容是:
const int ARRAY_SIZE=100;
class stack
{
public:
    void Init();
    void push(int newPush);
    int  Empty(){if(top=0) return 0;else return 1;};
    int Depth(){return top};
    int Pop();
    void Print() const;
private:
    int top;
    int elem[ARRAY_SIZE];
}
stack.cpp内容是:
# include <iostream.h>
# include "stack.h"
void stack::Init()
{
    top=0;
}
void stack::push(int newPush)
{
    if(top>ARRAY_SIZE)
    cout<<"栈溢出"<<endl;
    elem[top]=newPush;
    top=top+1;
}
int stack::Pop()
{
    return elem[top];
    top=top-1;
}
可是当stack.cpp编译时却出现了这样的问题:
f:\lian\stack.cpp(3) : error C2143: syntax error : missing ';' before 'PCH creation point'
执行 cl.exe 时出错.

stack.obj - 1 error(s), 0 warning(s)


在这里我谢谢你们的帮助,我已经解决了!

[[it] 本帖最后由 白杨树cy 于 2008-11-20 13:56 编辑 [/it]]
4 回复
#2
newyj2008-11-19 20:40
少 ; 号
int  Empty(){if(top=0) return 0;else return 1;};中的 top=0 改为top==0
#3
zqm02092008-11-19 20:40
类声明的花括号后面忘了加“;”了,细心
#4
白杨树cy2008-11-19 21:04
谢谢,虽然还没有成功的解决,但你们指点,还是受益非浅呀
#5
alweeq862008-11-21 22:57
if(top>ARRAY_SIZE)
    cout<<"栈溢出"<<endl;
lZ这句应该改为:
if(top=ARRAY_SIZE)
    cout<<"栈溢出"<<endl;
因为栈顶最大为ARRAY_SIZE-1
1