【问题标题】:Visual Studio 2012/2013 in-class member initializationVisual Studio 2012/2013 类内成员初始化
【发布时间】:2013-08-29 18:44:37
【问题描述】:

这个

class X
{
 int x = 2;
 string y {"smt"};
 int tab[3] = {1,2,3}; // or tab[3] {1,2,3}
};

据我所知,在新的 C++ 11 标准中是可能的。但是,在 Visual Studio 2012 V3 或 2013 中都不允许这样做。第一个给出:

error C2864: 'A::a' : only static const integral data members can be initialized within a class

关于 ';' 的第二个和第三个错误和'{'。

这基本上意味着这些功能在 MS 编译器中仍然不可用吗?什么编译器实际上支持它?我在 Visual 中搜索了有关类内初始化的答案,但没有找到有关最新版本的任何具体信息。

提前致谢。

【问题讨论】:

标签: c++ visual-studio-2012 c++11 visual-studio-2013


【解决方案1】:

不,Microsoft compiler 不支持非静态数据成员初始值设定项。 Herb Sutter 宣布它将在 Visual Studio 2013 RTM 中实现。 (Link)

先生。 Sutter 表示,延迟实现 C++11 功能的主要原因是微软试图同时实现 C++14 功能,因为它们是紧密耦合的。 所以,很可能,我们也会在 VS2013 版本中获得一些 C++14 特性。

其他主要编译器:

  • GCC 支持它(它是自 4.8.1 版本以来第一个完整的 C++11 兼容编译器)
  • Clang 从 3.0 版本开始支持
  • Intel 从版本 14 开始支持

【讨论】:

  • 谢谢,这也回答了我的其他几个问题。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-18
  • 1970-01-01
  • 1970-01-01
  • 2023-04-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多