Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has "In class member initialization" feature made into C++11?

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 ?

like image 233
iammilind Avatar asked Jun 26 '11 06:06

iammilind


Video Answer


1 Answers

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
};
like image 80
James McNellis Avatar answered Sep 20 '22 09:09

James McNellis