// foo.hpp file
class foo
{
public:
static const int nmConst;
int arr[nmConst]; // line 7
};
// foo.cpp file
const int foo::nmConst= 5;
Run Code Online (Sandbox Code Playgroud)
编译VC 2015返回错误:
1> foo.h(7):错误C2131:表达式没有求值为常量
1> 1> foo.h(7):失败是由非常量参数引起的或
引用非常量符号1> 1> foo.h(7):注意:看看'nmConst'的用法
为什么?nmConst是静态常量,其值在*.cpp文件中定义.