1 Star 2 Fork 0

岑剑伟 / CPlusPlusThings

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
nullptr.cpp 864 Bytes
一键复制 编辑 原始数据 按行查看 历史
//
// Created by light on 19-11-2.
//
#include <iostream>
using namespace std;
void f(int i) {
cout<<"void f(int i)" <<endl;
}
void f(void *p) {
cout<<"void f(void *p)" <<endl;
}
int main() {
f(0);
// #ifndef __cplusplus
// #define NULL ((void *)0)
// #else /* C++ */
// #define NULL 0
// c语言中将NULL定义为空指针,而在c++中直接定义为0,这是因为C++是强类型的,void *是不能隐式转换成其他指针类型的。
if(NULL==0) cout<<"NULL==0"<<endl;
// f(NULL); // ambiguous,因为NULL==0所以存在二义性 指针也可以是个int的地址
// c++11 空指针nullptr
f(nullptr); //typedef decltype(nullptr) nullptr_t;
// nullptr_t为nullptr的类型
nullptr_t nl; // 使用nullptr_t定义的任何变量都具有nullptr一样的行为
f(nl);
return 0;
}
C++
1
https://gitee.com/genvex/CPlusPlusThings.git
git@gitee.com:genvex/CPlusPlusThings.git
genvex
CPlusPlusThings
CPlusPlusThings
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891