之前:
在C ++ 98,C ++ 03中-非静态数据成员初始化程序(NSDMI)不存在。
https://wandbox.org/-在线编译器,您可以更改gcc版本等。
好的,现在让我们考虑一些代码(在c ++ 98或c ++ 03中):
#include <iostream>
struct test {
void *x = NULL;
void *y = 0; //with (void*)0 here, we get the same results
};
int main() {
std::cout<<(int)NULL;
}
Run Code Online (Sandbox Code Playgroud)
从gcc 4.8.1开始:
void *x = NULL;
允许(意外),但
void *y = 0;
不是(按预期)。//得到“ non-static data member initializers only available with -std=c++11 or -std=gnu++11”警告
零问题是,为什么0!= NULL这里(我认为#define NULL 0,
或
#define NULL (void *)0)
主要问题是为什么在较新的gcc版本中,我们可以初始化:
void *x = NULL; …