Dam*_*ian 44 c++ constexpr c++11 visual-studio-2013
此constexpr代码未在Visual Studio 2013版本12.0.21005.1 REL中编译
是否有更新的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;
}
Run Code Online (Sandbox Code Playgroud)
编译输出:
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 ==========
Herb Sutter在他的博客上提到了constexpr,但目前还不清楚它的工作原理/工作原理是什么?http://herbsutter.com/2013/09/09/visual-studio-2013-rc-is-now-available/#comment-13521
Lig*_*ica 51
微软发布一个C++ 11兼容性表,在其下constexpr被清楚地标记为不是在Visual Studio 2013可用.
来源:谷歌visual studio constexpr
constexprVisual Studio 2013 RTM不支持,请参阅兼容性表.这不仅适用于RTM版本,也适用于Visual Studio更新.
如果您想坚持使用Visual Studio 2013,可以下载Visual C++编译器2013年11月的CTP,它带有一些新功能,请参阅MSDN博客.遗憾的是,Microsoft没有与最新的Visual Studio Update功能和CTP功能合并,并明确指出他们不打算这样做.
如果我们想要一切,我们需要等待Visual Studio 2015,请参阅MSDN博客关于VS 2015 Preview.
正如其他人提到的,2013 年 11 月客户技术预览 (CTP)将使您能够访问constexpr*
请注意,只需下载,您就需要将“平台工具集”更改为“Visual C++ Compiler Nov 2013 CTP (CTP_Nov2013)”才能使用新编译器。您可以通过打开项目的“属性页”并转到:“配置属性”>“常规”,然后更改“平台工具集”来完成此操作。
*关于您实际上可以访问哪些部分,存在一些相互矛盾的信息constexpr,但这绝对不是constexpr. 微软在此表示,2013 年 11 月的 CTP 增加了:
constexpr支持(构造函数除外)
微软在这里说它包含:
constexpr(成员函数除外)
我什至无法测试它是否支持成员函数,因为它绝对不支持任何类型的constexpr构造。例如,此代码在 2013 年 11 月的 CTP 中出现此错误:
错误 C2127:使用非常量表达式非法初始化“constexpr”实体
另请注意:在撰写本文时,Visual Studio 2015 预览版仍然不支持constexpr构造。祈祷最终版本的发布。
| 归档时间: |
|
| 查看次数: |
32351 次 |
| 最近记录: |