C++ 11从相同类类型的构造函数中调用构造函数

use*_*967 6 c++ constructor visual-studio-2010 visual-c++ c++11

有人告诉我,由于C++ 11的变化,以下内容是可能的:

class SomeType  {
int number;

public:
SomeType(int new_number) : number(new_number) {}
SomeType() : SomeType(42) {}
};
Run Code Online (Sandbox Code Playgroud)

但是当我尝试构建时,我收到一个错误:

"SomeType" is not a nonstatic data member or base class of class "SomeType"

error C2614: 'SomeType' : illegal member initialization: 'SomeType' is not a base or member
Run Code Online (Sandbox Code Playgroud)

Visual Studio 2010中是否还不支持此功能?我是否需要配置一些东西来构建它?怎么了?

Dav*_*vid 10

VS2010不支持它.VS2010(或VS11)不支持大多数C++ 11功能

以下是VC10和VC11中支持的功能的图表.

  • @brendanw:C++ 11已经有很长一段时间了.GCC 4.3早在2008年就已经支持rvalue引用和可变参数模板(比如VS10发布前3年)(并且VS10发货*没有*variadic模板支持,现在,在2012年,VS11仍然不支持它.)GCC 2010年有一个lambdas,比VS10做了一年(并且VS10中的lambda是有缺陷的).现在,2012年VS11即将推出支持不良的C++ 11,而GCC 4.7于3月发布,几乎完全支持C++ 11.我不认为运气与它有关. (3认同)