关于 VC6.0的 Compiler Error C2057,疑惑啊,请高手指教
(注,我的VC6已经打了最新的ServicePack)
有以下代码,不能通过编译,报Compiler Error C2057
int num;
...
const int number = num;
double p[number]; //Error C2057
我查阅了MSDN,有关说明如下:
Visual C++ Concepts: Building a C/C++ Program
Compiler Error C2057
expected constant expression
The context requires a constant expression. The following sample generates C2057:
// C2057.cpp
int i;
// use the line below to resolve the error
// const int i = 8;
int b[i]; // C2057
int main() {
}
接着,小弟我带着非常疑惑的心情,做了如下的实验:
首先把const int number = num;改为const int number = 8; //随便什么整数常量都行
编译,通过;
然后再把const int number = 8;改回来const int number = num;
再编译,就通过了.
运行程序,行为正常.
到底是为什么啊?请诸位高手指教.