完全模仿nullptr [英] Perfectly emulate 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>错误编译器错误?
是运算符==
(和!= $ c $需要更完美地模拟
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中编译良好a>。
You compiled it with C++0x compiler that failed for unknown reason. It compiles fine in C++03.
这篇关于完全模仿nullptr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!