nullptr与NULL
NULL
NULL can be defined as any null pointer constant. Thus existing code can retain definitions of NULL as 0 or 0L, but an implementation may also choose to define it as (void*)0. This latter form of definition is convenient on architectures where sizeof(void*) does not equal the size of any integer type. It has never been wise to use NULL in place of an arbitrary pointer as a function argument, however, since pointers to different types need not be the same size. The library avoids this problem by providing special macros for the arguments to signal, the one library function that might see a null function pointer.
nullptr
A null pointer constant is an integer literal (2.13.2) with value zero or a prvalue of type std::nullptr_t.
A null pointer constant can be converted to a pointer type; the result is the null pointer value of that type and is distinguishable from every other value of object pointer or function pointer type. Such a conversion is called a null pointer conversion. Two null pointer values of the same type shall compare equal. The conversion of a null pointer constant to a pointer to cv-qualified type is a single conversion, and not the sequence of a pointer conversion followed by a qualification conversion (4.4). A null pointer constant of integral type can be converted to a prvalue of type std::nullptr_t. [ Note: The resulting prvalue is not a null pointer value. —end note ]
A prvalue of type “pointer to cv T,” where T is an object type, can be converted to a prvalue of type “pointer to cv void”. The result of converting a non-null pointer value of a pointer to object type to a “pointer to cv void” represents the address of the same byte in memory as the original pointer value. The null pointer value is converted to the null pointer value of the destination type.
A prvalue of type “pointer to cv D”, where D is a class type, can be converted to a prvalue of type “pointer to cv B”, where B is a base class (Clause 10) of D. If B is an inaccessible (Clause 11) or ambiguous (10.2) base class of D, a program that necessitates this conversion is ill-formed. The result of the conversion is a pointer to the base class subobject of the derived class object. The null pointer value is converted to the null pointer value of the destination type.
nullptr与NULL的更多相关文章
- nullptr和NULL
nullptr是c++11中的关键字,表示空指针 要区分nullptr和NULL,首先要明白NULL的含义: NULL是一个宏定义,在c和c++中的定义不同,c中NULL为(void*)0,而c++中 ...
- C++ nullptr 和 NULL 的使用区别
1. 为什么会有nullptr的出现 目的:nullptr的出现主要是为了替代NULL. 那么,为什么要替代NULL呢? 在NULL的定义中存在会有2种方式,有的编译器会将NULL定义成0,有的编译器 ...
- nullptr和NULL 区别
注:本文内容摘自网络,准确性有待验证,现阶段仅供学习参考.尊重作品作者成果,原文链接 :http://www.2cto.com/kf/201302/190008.html 1.为什要有nullptr ...
- 优先选择nullptr而不是0和NULL
我们知道:0是一个int,而不是一个指针.如果C++在一个只有指针才能够使用的上下文中发现它只有一个0,那么它会勉强将0解释成空指针,但那时一种倒退行为.C++的主要方针是0就是一个int,而不是指针 ...
- item 8: 比起0和NULL更偏爱nullptr
本文翻译自modern effective C++,由于水平有限,故无法保证翻译完全正确,欢迎指出错误.谢谢! 博客已经迁移到这里啦 先让我们看一些概念:字面上的0是一个int,不是一个指针.如果C+ ...
- Pointer's NULL And 0
问题起源 在使用Qt框架的时候, 经常发现一些构造函数 *parent = 0 这样的代码. 时间长了, 就觉的疑惑了. 一个指针不是等于NULL吗? 这样写, 行得通吗? 自己测试一下就可以了. 测 ...
- C++11 之 nullptr
C++11 中,nullptr 是空指针,可用来给 (指向任意对象类型的) 指针赋值 广义整型 (integral types) = char, short, int, long, long long ...
- 【C++11新特性】 nullptr关键字
原文链接:http://blog.csdn.net/xiejingfa/article/details/50478512 熟悉C++的童鞋都知道,为了避免“野指针”(即指针在首次使用之前没有进行初始化 ...
- C++ 11 nullptr关键字
熟悉C++的童鞋都知道,为了避免“野指针”(即指针在首次使用之前没有进行初始化)的出现,我们声明一个指针后最好马上对其进行初始化操作.如果暂时不明确该指针指向哪个变量,则需要赋予NULL值.除了NUL ...
随机推荐
- 鲜贝7.3--pycharm切换
在pycharm中切换python版本 打开软件会看到,这里有明显的红色提示错误.原因是当前使用的是python3.3,当执行print的时候,打印的文字需要小括号’()‘括起来. 在工具栏中找到这个 ...
- 牛客小白月赛18 Forsaken喜欢数论
牛客小白月赛18 Forsaken喜欢数论 题目传送门直接点标题 Forsaken有一个有趣的数论函数.对于任意一个数xxx,f(x)f(x)f(x)会返回xxx的最小质因子.如果这个数没有最小质 ...
- LG3119 「USACO2015JAN」Grass Cownoisseur
问题描述 LG3119 题解 显然,如果有个环,一定是全部走完的. 所以缩点,缩出一个 \(\mathrm{DAG}\) . 只能走一次反向,于是在正图和反图上各跑一次,枚举边,取 \(\mathrm ...
- WinSxS目录下文件的清除
1)McAfee Scanner service 持续高cpu 2)上网查到了,需要看 %deflogdir%目录下的OnDemandScan_Activity.log 3) 打开这个文件,发觉一直在 ...
- 突然看到原来除了jar包还有war包啊?????
先来说说区别: 首先,jar包呢,是一个压缩文件,可以由很多文件压缩而成,,简单来说就是,jar包是别人写好的一些类,然后对这些类 进行打包,这就是jar包,你可以直接用这些 jar包,使用里面的类 ...
- vue 使用watch监听实现类似百度搜索功能
watch监听方法,watch可以监听多个变量,具体使用方法看代码: HTML: <!doctype html> <html lang="en"> < ...
- antd模块组件文档思维导图整理
- 海边拾贝-E-第三方专栏文章
收录一些优秀的专栏文章,或者解决某类知识点的文章: Linux高性能服务器编程:https://blog.csdn.net/gatieme/column/info/high-per-server ht ...
- C# 匿名回调方法在循环体中使用的注意事项
今天在做AVG工具的选择分支功能时发现了一个问题,先把代码贴上来: private void SelectionParse(string value) { string[] ss = value.Sp ...
- 用Java开发的【智能语音开发板MEGA ESP32AI】
有点激动 ~ ~ ~ 新鲜出炉,用视频看看效果哦 我们新研发出世的语音开发板MEGA ESP32AI,来看看吧,有点腻害哦!!!先演示下功能语音控制开关等.播报天气 戳下面链接看视频哦? MEGA E ...