首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

VC2005 C++ malloc有关问题

2012-03-29 
VC2005 C++ malloc问题#include stdlib.h#include stdio.h//函数结果状态#define TRUE 1#define FALSE

VC2005 C++ malloc问题
#include "stdlib.h"
#include "stdio.h"

//函数结果状态
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
#define NULL 0

typedef int Status;
  //Status 其值是ERROR、OK、OVERFLOW
typedef int Bool;
  //Bool是布尔类型,其值是true和false
  //bool是C++标准类型

//----- 栈的顺序存储表示 -----
  #define STACK_INIT_SIZE 100; 
  #define STACKINCREMENT 10;  
 
 typedef char SElemType;
 // 按照问题所需设置SElemType的类型是char或其他类型

 typedef struct {
  SElemType *base;  
  SElemType *top;  
  int stacksize;  
  } SqStack;

Status InitStack(SqStack *S);
int main()
{
  SqStack Ss;
  if(InitStack(&Ss)==OK) printf("initial Stack OK.");
  return 0;
}

tatus InitStack(SqStack* S){
  // 构造一个空栈S
  SElemType *p=(SElemType *) malloc (STACK_INIT_SIZE * sizeof(SElemType)); 
  if (!p) exit(OVERFLOW) ; //存储分配失败
  S->top = S->base=p;
  S->stacksize = STACK_INIT_SIZE;
  return OK;
}

int main()
{
  SqStack Ss;
  if(InitStack(&Ss)==OK) printf("initial Stack OK.");
  return 0;
}

我的程序中,“ElemType *p=(SElemType *) malloc (STACK_INIT_SIZE * 

sizeof(SElemType)); ”在第69行
显示错误如下:

错误1error C2143: syntax error : missing ')' before ';'

d:\cplus\ch3-stack\stack.cpp69
错误2error C2100: illegal indirection

d:\cplus\ch3-stack\stack.cpp69
错误3error C2059: syntax error : ')'d:\cplus\ch3-

stack\stack.cpp69


[解决办法]
#define STACK_INIT_SIZE 100;
#define STACKINCREMENT 10;

把分号去掉。

热点排行