完全模仿nullptr [英] Perfectly emulate nullptr

查看:155
本文介绍了完全模仿nullptr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我厌倦了等待编译器支持 nullptr

I got tired of waiting for compiler support of nullptr (gcc 4.6 does but it's so new few distributions support it).

因此,作为一个停止间隙,直到 nullptr 是完全支持我决定模仿它。有两个仿真示例:一个来自此处,一个来自 wikibooks

So as a stop gap until nullptr is fully supported I decided to emulate it. There are two examples of emulation: one from here, and one from wikibooks.

值得注意的是,两个实现都没有提到 operator == 。但是,如果没有其他代码,将无法编译

Of note, neither implementation mentions an operator ==. However, without one, the following code will not compile.

int* ptr = nullptr;
assert( ptr == nullptr ); // error here: missing operator ==

这是 / code>错误编译器错误?

运算符== (和!= nullptr的 ,<=

模拟的 nullptr 与真实交易之间还有什么不同?

Is this operator == error a compiler bug?
Is operator == (and !=, <, <=, etc) needed to more perfectly emulate nullptr?
What else is different between an emulated nullptr and the real deal?

推荐答案

您使用C ++ 0x编译器编译失败的未知原因。它在C ++ 03中编译良好

You compiled it with C++0x compiler that failed for unknown reason. It compiles fine in C++03.

这篇关于完全模仿nullptr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆