2

带有如下所示语句的代码可以使用 g++.exe(x86_64-posix-seh-rev4,由 MinGW-W64 项目构建)4.8.2 编译,但不能使用最新的Visual Studio 2013 Update 3 CTP 2 (12.0.306020.00更新 3 CTP)

问题:我可能做错了什么,比如没有打开某些功能,或者最新的 Visual Studio 2013 不支持这样的陈述吗?代码需要在 Visual Studio 下编译——关于如何解决这个限制的任何建议?

namespace NA
{
   namespace NB
   {
      class C1 : P1
      {
         static constexpr double one     = 1.0;
         static constexpr double two     = one + one;
         static constexpr float  a_foo[][2]  =  { { 1.0, 1.1, 1.2 },
                                                  { 2.0, 2.1, 2.2 } };

         static constexpr int    n_ele   = 1024;
         static constexpr int    n_d     = 128;
         static constexpr int    n_ape   = n_ele -
                                           n_d  +
                                           1;

         std::vector< std::array< int, (int)n_ele >> ape
         {
            std::vector< std::array< int, (int)n_ele >>
            ( (int)n_ape,  {{0}} )
         };

         std::array<
                      std::array< int,  (int)n_d >,
                      (int)n_ape
                   >  c_to_e = {{ std::array< int, (int)n_d >( {0} ) }};
      }
   }
}
4

2 回答 2

4

根据这篇博客C++11constexpr被列为 Partial是因为 VS 在成员函数上不支持它。

C++14constexpr支持在一个单独的行中,其含义尚未实现。

所以我想,我们将不得不等待constexpr功能完全实现的新版本。

于 2014-06-25T14:02:12.777 回答
1

Visual C++ 2013 根本不支持 constexpr。对于 Visual C++,您可以使用“static const”而不是“static constexpr”。

于 2014-06-25T14:53:30.633 回答