According to the C++0x spec, the following is legal
class A {
A(int i) : x(i) {}
A() : A(0) {}
int x;
};
But it fails to compile ("A" is not a nonstatic data member or base class of class "A"
) in VC 2010. Anyone know what's wrong?
According to the C++0x spec, the following is legal
class A {
A(int i) : x(i) {}
A() : A(0) {}
int x;
};
But it fails to compile ("A" is not a nonstatic data member or base class of class "A"
) in VC 2010. Anyone know what's wrong?
Visual C++ 2010 (also known as VC++ 10.0) as of this writing does not support delegating constructors, which is what your code snippet requires. VC++ 10.0 only has partial support for C++0x, and as of this writing, no compiler has implemented the entire C++0x feature set (although that will change soon, especially once the C++0x standard is finalized).
Scott Meyers have a summary of C++0x support in gcc and MSVC compilers. Here's another list of C++0x feature support in different compilers. Also, a list of C++0x features supported in Visual C++ 2010 straight from the horse's mouth.
For now, initialize all members directly in the initialization list of your constructors:
class A
{
public:
A(int i) : x(i) {}
A() : x(0) {}
private:
int x;
};
Visual Studio doesn't support all of 0x yet. (And nobody should be expected to; 0x isn't finalized.)
MSVC++ 2010 doesn't have support for delegating constructor
This page lists C+ 0x features and their support in popular compilers.