#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<math.h>
# define MAXSIZE 100
typedef struct{
int *top; //栈顶指针
int *base; //栈底指针
int stacksize; //栈容量
}SqStack;
void Initstack(); //构造一个空栈
void main(){
SqStack S;
InitStack(S);
system("pause");
}
void InitStack(SqStack &S){ //构造一个空栈
S.base=(int *)malloc(MAXSIZE*sizeof(int));
if(!S.base) exit(0); //存储空间失败
S.top=S.base;
S.stacksize=MAXSIZE;
}
可是为什么编译还是出错啊?
追答提供错误图片,我在VC6通过了的
追问你把程序名的扩展名改成.cpp
因为.c时,是按c语言进行编译,C语言不支持引用 &这个符号!!
引用是C++引入的新特性!表示使用变量的别名
我检查了下面网友的代码,这应该是没有问题的,问题可能是你的编译器,我给你把这段代码改成用标准c写的,再编译不通过可没办法了。
#include<stdio.h>问题已解决,谢谢,不过为什么你们的编译器能通过我的确不行呢?我用的VC6.0
追答尽量用cpp格式, c++的特性更多一些,