小编mar*_*k01的帖子

= NULL,并且非静态数据成员在c ++ 98中初始化

之前:
在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; …

c++ gcc c++03 c++98

5
推荐指数
1
解决办法
74
查看次数

标签 统计

c++ ×1

c++03 ×1

c++98 ×1

gcc ×1