【问题标题】:Using nullptr gets an error in Codeblocks IDE在 Codeblocks IDE 中使用 nullptr 会出错
【发布时间】:2015-03-14 04:42:05
【问题描述】:

在我的代码中使用nullptr 时,它不起作用。虽然可能有其他线程和东西可以解释,但我尝试了几个,但效果不佳。我正在关注 SFML/C++ 教程,这里是代码:

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();
  }
}

错误如下:error: 'nullptr' was not declared in this scope.

nullptr 的轮廓为蓝色,但在我输入一半的工作时出现。

【问题讨论】:

    标签: c++


    【解决方案1】:

    nullptr 是 C++11 功能。因此,您需要在 C++11 模式下编译代码才能使用它。请参阅here 如何做到这一点。

    【讨论】:

      猜你喜欢
      • 2018-02-24
      • 1970-01-01
      • 1970-01-01
      • 2019-03-07
      • 2013-11-11
      • 2020-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多