在某个大佬编程的代码中看到Q_NULLPTR,查文档查不到它的用处,终于在外国论坛看到讲解,我觉得最合适的解释如下:
Q_NULLPTR is a macro,that is replaced as nullptr if compiler supports c++11 and as NULL (which is replaced as 0)if it doesn’t.If you use c++11,you can write nullptr instead; use NULL if you don’t.
(翻译:Q_NULLPTR是一个宏,如果编译器支持c++11,则替换为NULLPTR;如果不支持,则替换为NULL(替换为0)。如果使用c++11,则可以编写NULLPTR;如果不支持,则使用NULL)
简单的说,编译器支持C++11,会变为nullptr,不支持变为NULL。所以直接用nullptr就好了。
本文解析了Q_NULLPTR宏的作用及其在不同C++版本中的表现形式。当编译器支持C++11时,Q_NULLPTR会被替换成nullptr;反之则被替换成NULL(即0)。对于现代C++编程,推荐直接使用nullptr。
890





