Anixx
Anixx

Reputation: 139

"'nullptr' was not declared in this scope" in GCC 7.5

I am using GCC 7.5. When building packages, it complains about ordered comparison between integer and pointer, so I change the 0 in the comparison to nullptr.

But then I receive an error message that "'nullptr' was not declared in this scope".

Trying adding options -std=c++11 or -std=c++14 does not help.

All the programs are in C++.

Upvotes: 0

Views: 190

Answers (1)

n. m. could be an AI
n. m. could be an AI

Reputation: 119877

it complains about ordered comparison between integer and pointer

"Ordered comparison" means comparison with > or < or >= or <=. It makes no sense to compare a pointer with a null pointer constant this way.

so I change the 0 in the comparison to nullptr

This doesn't make the comparison any more meaningful. It makes no sense to compare a pointer with a null pointer constant this way either.

But then I receive an error message that "'nullptr' was not declared in this scope".

This cannot happen with gcc 7.5 unless you

  • compile C rather than C++ or
  • pass -std=c++98 or -std=c++03 somewhere or
  • have a broken installation of gcc.

In any case you probably want to fix the comparison (perhaps change > or < to !=) and only then think of maybe replacing 0 with nullptr.

Upvotes: 1

Related Questions