【发布时间】:2014-05-01 01:55:24
【问题描述】:
Visual Studio 2013 中的以下代码导致错误 C2057:
#include <cmath>
int main() {
static_assert(std::pow(2, 2) < 5, "foobar");
return 0;
}
错误 C2057:预期的常量表达式
如果我在 GCC -std=c++0x 下编译它可以正常工作。 http://ideone.com/2c4dj5
如果我将std::pow(2, 2) 替换为4,它也会在Visual Studio 2013 下编译。
- 这是 VS2013 的错误吗?
- 我该如何解决这个问题?
【问题讨论】:
-
Visual C++ 2013 不支持
constexpr。但即使是这样,pow也不需要是constexpr,因此您的代码充其量是不可移植的,并且依赖于实现扩展。
标签: c++ c++11 visual-studio-2013 static-assert