问题
Related: Eclipse CDT "Symbol NULL could not be resolved"
I was under the impression that NULL was a standard macro in C++ and didn't need any headers to be included. Eclipse, on the other hand, thinks it doesn't exist.
Is there some way to remind Eclipse that I'm in C++ mode not C mode for this file, and therefore to shut up about the NULL problem?
回答1:
I was under the impression that NULL was a standard macro in C++.
It is, but it's not part of the language. You still need to include <cstddef> or <cstdlib>, etc.
回答2:
Why is NULL undeclared?
Quoted from the top-answer on that question.
NULL is not a built-in constant in the C or C++ languages. In fact, in C++ it's more or less obsolete, just use a plain literal 0 instead, the compiler will do the right thing depending on the context.
Otherwise, add
#include <stddef.h>to get the NULL definition.
UPDATE: I had the wrong header, corrected now. Thanks! (Quoted from Unwind)
来源:https://stackoverflow.com/questions/10955343/eclipse-cdt-c-null-not-resolved