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

类型定义未能通过编译~该如何解决

2012-04-05 
类型定义未能通过编译~?4:constintMAXLEN100005:typedefintELEMENT6:typedefELEMENTSTACK[MAXLEN]7:in

类型定义未能通过编译~?
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.

热点排行