【发布时间】:2015-11-10 07:54:41
【问题描述】:
// foo.hpp file
class foo
{
public:
static const int nmConst;
int arr[nmConst]; // line 7
};
// foo.cpp file
const int foo::nmConst= 5;
编译器 VC 2015 返回错误:
1>foo.h(7):错误 C2131:表达式未计算为常量
1> 1>foo.h(7): 失败是由非常量参数或
引用非常量符号 1> 1>foo.h(7):注意:请参阅 'nmConst'
为什么? nmConst 是静态常量,其值在 *.cpp 文件中定义。
【问题讨论】: