What exactly is nullptr?

前端 未结 14 2721
无人及你
无人及你 2020-11-22 01:12

We now have C++11 with many new features. An interesting and confusing one (at least for me) is the new nullptr.

Well, no need anymore for the nasty mac

14条回答
  •  青春惊慌失措
    2020-11-22 01:31

    From nullptr: A Type-safe and Clear-Cut Null Pointer:

    The new C++09 nullptr keyword designates an rvalue constant that serves as a universal null pointer literal, replacing the buggy and weakly-typed literal 0 and the infamous NULL macro. nullptr thus puts an end to more than 30 years of embarrassment, ambiguity, and bugs. The following sections present the nullptr facility and show how it can remedy the ailments of NULL and 0.

    Other references:

    • WikiBooks, with sample code.
    • Here at Stack Overflow: Do you use NULL or 0 (zero) for pointers in C++?
    • template
    • Google group: comp.lang.c++.moderated - compiler discussion

提交回复
热议问题