這constexpr代碼編譯沒有沒有在Visual Studio 2013版本編譯12.0.21005.1 RELconstexpr在VC2013
是否有新的Visual Studio編譯器對使用constexpr的作品?從編譯
#include <iostream>
constexpr int factorial(int n)
{
return n <= 1 ? 1 : (n * factorial(n - 1));
}
int main(void)
{
const int fact_three = factorial(3);
std::cout << fact_three << std::endl;
return 0;
}
輸出:
1>------ Build started: Project: Project1, Configuration: Debug Win32 ------ 1> Source.cpp 1>....\source.cpp(3): error C2144: syntax error : 'int' should be preceded by ';' 1>....\source.cpp(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
香草薩特提到在他的博客constexpr,但目前還不清楚它的工作原理是什麼版本/是否行得通呢? http://herbsutter.com/2013/09/09/visual-studio-2013-rc-is-now-available/#comment-13521
你需要讓[2013 CTP(http://blogs.msdn.com/b/vcblog/archive /2013/11/18/announcing-the-visual-c-compiler-november-2013-ctp.aspx),儘管注意它仍然不完整(尚未爲成員函數實現))。 –
編譯並運行良好的gcc版本4.8.2(GCC)爲cygwin,--std = C++ 11 – RichardPlunkett
是2013 CTP的工作就像一個魅力! ;-) – Damian