I have the following error.

#include <iostream>

void doAnything(int *ptr)
{
if (ptr)
std::cout << "You passed in " << *ptr << '\n';
else
std::cout << "You passed in a null pointer\n";
}

int main()
{
doAnything(nullptr);//[Error] 'nullptr' was not declared in this scope

return 0;
What compiler and version are you using?
this is likely an old compiler or a missing compiler flag to enable c++11 or c++17 or whatever. nullptr is a full keyword and unlike null does not need an include to work, so the only cause of this I can think of would be the compiler not seeing it as a keyword, which implies age or flag.
PLEASE, do not double-post.

http://www.cplusplus.com/forum/general/263640/

And learn to use code tags, it makes reading and commenting on your source code MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/

Hint: you can edit your post and add them.
Last edited on
Topic archived. No new replies allowed.