3

When using nullptr in my code, it doesn't work. Whilst there may be other threads and stuff that may explain, I've tried a couple and they didn't work well. I'm following a SFML/C++ Tutorial, and here is the code:

GameState * Game::peekState() {
  if (this - > states.empty()) return nullptr;
  return this - > states.top();
}

void Game::gameLoop() {
  sf::Clock clock;

  while (this - > window.isOpen()) {
    sf::Time elapsed = clock.restart();
    float dt = elapsed.asSeconds();

    if (peekState() == nullptr) continue;
    peekState() - > handleInput();
    peekState() - > update(dt);
    this - > window.clear(sf::Color::Black);
    peekState() - > draw(dt);
    this - > window.display();
  }
}

The error is as follows: error: 'nullptr' was not declared in this scope.

nullptr is outlined blue and showed up when I typed half of the work however.

Praetorian
  • 103,386
  • 18
  • 232
  • 318
Kataware
  • 167
  • 2
  • 3
  • 11

1 Answers1

8

nullptr is a C++11 feature. You thus need to compile your code in C++11 mode to use it. See here how to do that.

Community
  • 1
  • 1
Baum mit Augen
  • 47,658
  • 24
  • 139
  • 177