所以我收到了这个错误:game.cpp(15): error C3867: 'sf::Window::isOpen': non-standard syntax; use '&' to create a pointer to member
Game.cpp
#include "Game.h"
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
Game::Game() :
window(sf::VideoMode(200, 200), "SFML works!"),
player()
{
player.setRadius(40.f);
player.setPosition(100.f, 100.f);
player.setFillColor(sf::Color::Cyan);
}
void Game::run() {
while (window.isOpen) {
processEvents();
update();
render();
}
}
void Game::processEvents()
{
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
}
}
void Game::update() {
}
void Game::render() {
window.clear();
window.draw(player);
window.display();
}
这是我的game.h
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
class Game {
public:
Game();
void run();
sf::RenderWindow window;
sf::CircleShape player;
private:
void processEvents();
void update();
void render();
};
我不知道我做错了什么,我通过其他stackoverflow回答相同的错误,但它们都是一般的,他们不帮我修复这个错误,因为它来自SFML库。如果有人知道如何解决它,请帮助我:)
答案 0 :(得分:2)
这里while (window.isOpen)
您正在测试成员函数指针'window.isOpen'不是nullptr
。您打算调用函数while (window.isOpen())
。