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
  • 106,671
  • 19
  • 240
  • 328
Kataware
  • 167
  • 2
  • 5
  • 11

1 Answers1

9

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
  • 49,044
  • 25
  • 144
  • 182