C++之‘nullptr’ was not declared in this scope

207 阅读1分钟

在vim里面写了一个简单cpp文件,为了避免野指针,需要指针初始化

 

char *p2 = nullptr

 

 

 

1、编译时报错如下

 

 

 

 

2、解决办法

编译加上

 

g++ -std=gnu++0x int.cpp -o int

 

 

 

 

3、C里面的null和C++里面的nullptr、NULL介绍

NULL在C++中的定义

 

/* Define NULL pointer value */
#ifndef NULL
    #ifdef __cplusplus
        #define NULL    0
    #else  /* __cplusplus */
        #define NULL    ((void *)0)
    #endif  /* __cplusplus */
#endif  /* NULL */