C++11 calling constructor from constructor of same class type

我们两清 提交于 2019-12-14 00:48:48

问题


I was told the following was possible due to changes in C++11:

class SomeType  {
int number;

public:
SomeType(int new_number) : number(new_number) {}
SomeType() : SomeType(42) {}
};

But when I try to build I get an error:

"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

Is this feature not yet supported in Visual Studio 2010? Do I need to configure something to get this to build? What is wrong?


回答1:


It's not supported in VS2010. Most C++11 features are not supported in VS2010 (or VS11 for that matter)

Here is a chart of supported features in VC10 and VC11.



来源:https://stackoverflow.com/questions/10423401/c11-calling-constructor-from-constructor-of-same-class-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!