类型定义未能通过编译~?
4:const int MAXLEN=10000;
5:typedef int ELEMENT;
6:typedef ELEMENT STACK[MAXLEN];
7:int top=0;
想自己写写数据结构中关于栈的操作~
类型定义如上,便宜报错为
第6行 variable-size type declared outside of any function
不解,迷惑中……
[解决办法]
C++中的const与C里面的是不同的:(摘自thinking in C++)
Constants were introduced in early versions of C++ while the
Standard C specification was still being finished. Although the C
committee then decided to include const in C, somehow it came to
mean for them “an ordinary variable that cannot be changed.” In C,
a const always occupies storage and its name is global. The C
compiler cannot treat a const as a compile-time constant. In C, if
you say
const int bufsize = 100;
char buf[bufsize];
you will get an error, even though it seems like a rational thing to
do. Because bufsize occupies storage somewhere, the C compiler
cannot know the value at compile time.