【发布时间】:2016-06-01 16:41:03
【问题描述】:
错误代码是 C2131。
即使我在其他文件中调用此变量的大小时,intelisense 也不会抱怨 intelisense 知道大小。我缺少什么才能让这个工作?任何帮助是极大的赞赏。在下面的图片中看到 intelisense 没有抱怨并且还在确定大小。
示例 a.h:
class a
{
private:
static constexpr char m_pszFoo[] = "***FOO***"; // compile error on this line C2131 expression did not evaluate to a constant
public:
a() { sizeof(m_pszFoo); }; // no compile error here
};
要重现所有你需要做的就是在任何其他文件中包含 a.h。没有包含它不会重现。
【问题讨论】:
-
@NathanOliver 在 msvc 2015 14.0.24720.00 update 1 中验证了上述示例
-
我可以确认它不能在 MSVS 中编译。 clang 和 gcc 都可以编译。
-
尝试制作构造函数
constexpr -
嗨 @M.M constexpr 导致 sizeof 的另一个错误。 “语句可能不会出现在 constexpr 构造函数中。”这是你所期望的吗?如果是这样,它证明了什么?
标签: c++ visual-c++ visual-studio-2015