所以我得到这个错误:game.cpp(15): error C3867: 'sf::Window::isOpen': non-standard syntax;使用“&”创建指向成员的指针
游戏.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();
}
这是我的游戏.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 库。如果有人知道如何修复它,请帮助我:)
最佳答案
此处 while (window.isOpen)
您正在测试成员函数指针 'window.isOpen' 不是 nullptr
。您的意图是调用函数while (window.isOpen())
。
关于c++ - SFML 错误 - isOpen 非标准语法;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38209390/