本文介绍了constexpr 未在 VC2013 中编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

此 constexpr 代码未在 Visual Studio 2013 版本 12.0.21005.1 REL 中编译

This constexpr code does not compiled in Visual Studio 2013 version 12.0.21005.1 REL

是否有更新的 Visual Studio 编译器可以与 constexpr 配合使用?

Is there a newer Visual Studio compiler that works with 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 ==========

Herb Sutter 在他的博客上提到了 constexpr,但不清楚它在哪个版本中有效/将有效?http://herbsutter.com/2013/09/09/visual-studio-2013-rc-is-now-available/#comment-13521

Herb Sutter mentions constexpr on his blog but is unclear in what version it works / will work? http://herbsutter.com/2013/09/09/visual-studio-2013-rc-is-now-available/#comment-13521

推荐答案

微软发布了C++11兼容性表,其中constexpr明确标记为在 Visual Studio 2013 中不可用.

Microsoft publishes a C++11 compatibility table, under which constexpr is clearly marked as not being available in Visual Studio 2013.

2013 年 11 月的 CTP 已经有了.

这篇关于constexpr 未在 VC2013 中编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 09:21