struct A
{
int a = 5; //OK
const int b = 5; //OK
static const int c = 5; //OK
static int d = 5; //Error!
}
error: ISO C++ forbids in-class initialization of non-const static member 'A::d'
這是爲什麼?有人能向我解釋這背後的原因嗎?爲什麼初始化非const和靜態const成員變量而不是靜態成員變量?
static - 閱讀字典http://dictionary.reference.com/browse/static – 2014-10-04 05:51:33
在這個問題中提供的答案:http:// stackoverflow。com/questions/20310000/error-iso-c-forbids-class-non-const-static-member的初始化 – balajeerc 2014-10-04 05:53:28