[英]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
). 这在最新的编译器gcc-4.6中给出错误(使用-std=c++0x
)。 Has this feature made into the C++11 standard or gcc still doesn't support it ? 将此功能制作成C ++ 11标准还是gcc仍然不支持它?
Yes, that is legal in C++0x. 是的,这在C ++ 0x中是合法的。 There is an example of this at N3290 §12.6.2/8: 在N3290§12.6.2/ 8中有一个例子:
struct C {
/* ... */
int j = 5; // OK: j has the value 5
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.