error: ‘NULL’ was not declared in this scope

jackhab picture jackhab · Jan 20, 2009 · Viewed 164.3k times · Source

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.

Answer

Johannes Schaub - litb picture Johannes Schaub - litb · Jan 20, 2009

NULL is not a keyword. It's an identifier defined in some standard headers. You can include

#include <cstddef>

To have it in scope, including some other basics, like std::size_t.