Why is NULL undeclared?

前端 未结 5 1353
死守一世寂寞
死守一世寂寞 2020-11-30 02:55

I have a problem with this struct contructor when I try to compile this code:

typedef struct Node
{
    Node( int data ) //
    {
        this->data = dat         


        
5条回答
  •  眼角桃花
    2020-11-30 03:34

    Do use NULL. It is just #defined as 0 anyway and it is very useful to semantically distinguish it from the integer 0.

    There are problems with using 0 (and hence NULL). For example:

    void f(int);
    void f(void*);
    
    f(0); // Ambiguous. Calls f(int).
    

    The next version of C++ (C++0x) includes nullptr to fix this.

    f(nullptr); // Calls f(void*).
    

提交回复
热议问题