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!
NULL is not a built-in constant in the C or C++ languages.
NULL is defined in the following header files: CRTDBG. H, LOCALE. H, STDDEF. H, STDIO.
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.
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.)
You should include <stddef.h>
or <cstddef>
.
However you can use 0
or nullptr
too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With