问题
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