Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

Any help appreciated!

like image 409
Alon Shmiel Avatar asked Mar 21 '13 14:03

Alon Shmiel


People also ask

Is null undefined in C?

NULL is not a built-in constant in the C or C++ languages.

What header defines null in C?

NULL is defined in the following header files: CRTDBG. H, LOCALE. H, STDDEF. H, STDIO.

What does use of undeclared identifier mean in C?

The identifier is undeclaredIf the identifier is a variable or a function name, you must declare it before it can be used. A function declaration must also include the types of its parameters before the function can be used.


2 Answers

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.)

like image 72
metal Avatar answered Sep 20 '22 17:09

metal


You should include <stddef.h> or <cstddef>.

However you can use 0 or nullptr too.

like image 39
masoud Avatar answered Sep 19 '22 17:09

masoud