I get this message when compiling C++ on gcc 4.3
error: ‘NULL’ was not declared in this scope
It appears and disappears and I don't know why. Why?
Thanks.
I get this message when compiling C++ on gcc 4.3
error: ‘NULL’ was not declared in this scope
It appears and disappears and I don't know why. Why?
Thanks.
You can declare the macro NULL. Add that after your #includes:
or
No ";" at the end of the instructions...
NULL
is not a keyword. It's an identifier defined in some standard headers. You can includeTo have it in scope, including some other basics, like
std::size_t
.GCC is taking steps towards C++11, which is probably why you now need to include cstddef in order to use the NULL constant. The preferred way in C++11 is to use the new nullptr keyword, which is implemented in GCC since version 4.6. nullptr is not implicitly convertible to integral types, so it can be used to disambiguate a call to a function which has been overloaded for both pointer and integral types:
NULL can also be found in:
String.h will pull in the NULL from somewhere else.
NULL
isn't a keyword; it's a macro substitution for 0, and comes instddef.h
orcstddef
, I believe. You haven't#included
an appropriate header file, so g++ seesNULL
as a regular variable name, and you haven't declared it.To complete the other answers: If you are using C++11, use
nullptr
, which is a keyword that means a void pointer pointing to null. (instead ofNULL
, which is not a pointer type)