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;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With