![](/img/trans.png)
[英]Has the new C++11 member initialization feature at declaration made initialization lists obsolete?
[英]Has “In class member initialization” feature made into C++11?
在類初始化功能中 ,它允許在類本身內初始化普通成員,
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仍然不支持它?
是的,這在C ++ 0x中是合法的。 在N3290§12.6.2/ 8中有一個例子:
struct C {
/* ... */
int j = 5; // OK: j has the value 5
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.