在Visual Studio 2013下面的代碼導致錯誤C2057:std :: pow在static_assert觸發錯誤C2057?
#include <cmath>
int main() {
static_assert(std::pow(2, 2) < 5, "foobar");
return 0;
}
error C2057: expected constant expression
如果我編譯GCC -std=c++0x
下正常工作。 http://ideone.com/2c4dj5
如果我更換std::pow(2, 2)
與4
,還編譯的Visual Studio 2013年
- 這是一個VS2013的錯誤下?
- 我該如何解決這個問題?
Visual C++ 2013不支持'constexpr'。但即使這樣做,'pow'也不一定是'constexpr',所以你的代碼最好是不可移植的,並且依賴於實現擴展。 –