C ++ 11中是否有“In class member initialization”功能?

时间:2011-06-26 06:49:45

标签: c++ c++11 in-class-initialization

In class initialization feature,允许在类本身内初始化普通成员,

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

这在最新的编译器gcc-4.6(带-std=c++0x)中出错。将此功能制作成C ++ 11标准还是gcc仍然不支持它?

1 个答案:

答案 0 :(得分:23)

是的,这在C ++ 0x中是合法的。在N3290§12.6.2/ 8中有一个例子:

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