奇怪的问题,还是不行
这是栈类:
#include <stdlib.h>
#include <malloc.h>
#define STACK_INIT_SIZE 100;
#define STACKINCREMENT 10;
class Stack
{
public:
Stack(void);
~Stack(void);
int ClearStack(void);
int StackEmpty(void);
int StackLength(void);
int GetTop(void);
int Push(int);
int Pop(int &);
private:
int *base;
int *top;
int stacksize;
};
Stack::Stack(void)
{
base=(int *)malloc(STACK_INIT_SIZE*sizeof(int));
if (base==NULL) throw "Memory allocation failed";
top=base;
stacksize=STACK_INIT_SIZE;
}
Stack::~Stack(void)
{
free(base);
}
Stack::GetTop(void)
{
return *(top-1);
}
Stack::Push(int e)
{
if (top-base>=stacksize) {
base=(int *)realloc(base,((STACK_INIT_SIZE+STACKINCREMENT)*sizeof(int)));
if (base==NULL) throw "Memory allocation failed";
top=base+stacksize;
stacksize+=STACKINCREMENT;
}
*top++=e;
return 1;
}
Stack::Pop(int &e)
{
if (top==base) throw "Empty stack";
e=*--top;
return 1;
}
Stack::ClearStack(void)
{
top=base;
return 1;
}
Stack::StackEmpty(void)
{
if (base==top) return 1;
return 0;
}
Stack::StackLength(void)
{
return top-base;
}
在程序中调用,出错
e:\Backups\My Documents\Visual Studio Projects\stackdemo\stack.h(27): error C2143: syntax error : missing ')' before ';'
e:\Backups\My Documents\Visual Studio Projects\stackdemo\stack.h(27): error C2100: illegal indirection
e:\Backups\My Documents\Visual Studio Projects\stackdemo\stack.h(27): error C2059: syntax error : ')'
e:\Backups\My Documents\Visual Studio Projects\stackdemo\stack.h(47): error C2143: syntax error : missing ')' before ';'
e:\Backups\My Documents\Visual Studio Projects\stackdemo\stack.h(47): error C2143: syntax error : missing ')' before ';'
e:\Backups\My Documents\Visual Studio Projects\stackdemo\stack.h(47): error C2143: syntax error : missing ')' before ';'
e:\Backups\My Documents\Visual Studio Projects\stackdemo\stack.h(47): error C2059: syntax error : ')'
e:\Backups\My Documents\Visual Studio Projects\stackdemo\stack.h(47): error C2100: illegal indirection
e:\Backups\My Documents\Visual Studio Projects\stackdemo\stack.h(47): error C2059: syntax error : ')'
e:\Backups\My Documents\Visual Studio Projects\stackdemo\stack.h(47): error C2059: syntax error : ')'
错误全是出在那两行内存分配上,请大哥帮我看看:) 我用的vs7+2kserver 写的基于对话框的mfc程序