Is it safe to #define NULL nullptr?

前端 未结 6 847
囚心锁ツ
囚心锁ツ 2021-02-02 06:38

I have seen below macro in many topmost header files:

#define NULL 0  // C++03

In all over the code, NULL and 0 are u

6条回答
  •  北海茫月
    2021-02-02 07:13

    Maybe Not

    If you have a particular format of overloading behaviour:

    void foo(int);
    void foo(char*);
    

    Then the behaviour of the code:

    foo(NULL);
    

    will change depending on whether NULL is changed to nullptr or not.

    Of course, there's another question as to whether it's safe to write such code as is present in this answer...

提交回复
热议问题