12

In class initialization feature, which allows to initialize normal members inside the class itself,

struct A {
  int a = 0; // error: ISO C++ forbids in-class initialization of non-const static member ‘a’
};

This is giving error in latest compiler gcc-4.6 (with -std=c++0x). Has this feature made into the C++11 standard or gcc still doesn't support it ?

4
  • 3
    Your example compiles fine with clang (svn trunk).
    – Arzar
    Commented Jun 26, 2011 at 10:22
  • Have you tried with gcc 4.7 ? It may have been incorporated in. Commented Jun 26, 2011 at 11:21
  • @Matthieu, with lots of effort I somehow installed gcc-4.6 on installed on Ubuntu a week back, assuming it supports all the features. And now I am learning that gcc-4.7 is already released !! :'(
    – iammilind
    Commented Jun 26, 2011 at 11:27
  • 1
    I just looked at the release notes (gcc.gnu.org/gcc-4.7/changes.html) and it does not seem to have make it in 4.7. Honestly, I find the 4.7 rather light in term of changes (for C++ anyway) though I guess reviewing the two-phase lookup of templates implied some effort! Commented Jun 26, 2011 at 11:39

1 Answer 1

23

Yes, that is legal in C++0x. There is an example of this at N3290 §12.6.2/8:

struct C {
    /* ... */
    int j = 5; // OK: j has the value 5
};

Not the answer you're looking for? Browse other questions tagged or ask your own question.