Search code examples
c++pointersnull

set head to NULL ('NULL' : undeclared identifier)


I defined a linked list in C++. I am trying to set a NULL value to the variable head (in the constructor of Movie_LinkedList), but I got:

movie.h(40): error C2065: 'NULL' : undeclared identifier

please note that I can't include any library except of iostream

#define NAME_LEN 100

class Movie_DataBase
{
private:
    long int m_Code;
    char m_Name[NAME_LEN];
    bool belongs_to_netwroks[2];    
public:
    Movie_DataBase();
    Movie_DataBase(char movie_name[],long int movie_code);
};


class Movie_LinkedList
{
private:
    class Movie_Node
    {
    public:
        Movie_DataBase* data;
        Movie_Node* prev;
        Movie_Node* next;
    public:
        Movie_Node();

    };
    Movie_Node* head; //pointer to the first node in the linkedlist
    int a;
public:
    void set_movie();
    Movie_LinkedList() { head = NULL; }

};

Any help appreciated!


Solution

  • As written, NULL isn't defined in your program. Usually, that's defined in a standard header file -- specifically <cstddef> or <stddef.h>. Since you're restricted to iostream, if yours doesn't get NULL implicitly from that header, you can use 0 or, in C++11, nullptr, which is a keyword and doesn't require a header. (It is not recommended to define NULL yourself. It might work sometimes, but it is technically illegal.)