SFML 错误 - isOpen 非标准语法;
SFML Error - isOpen non-standard syntax;
所以我收到了这个错误: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();
};
我不知道我做错了什么,我查看了其他 Whosebug 对同一错误的回答,但它们都是一般性的,它们无法帮助我修复此错误,因为它来自 SFML 库。如果有人知道如何修复它,请帮助我:)
此处while (window.isOpen)
您正在测试成员函数指针'window.isOpen'不是nullptr
。您的意图是 调用 函数 while (window.isOpen())
。
所以我收到了这个错误: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();
};
我不知道我做错了什么,我查看了其他 Whosebug 对同一错误的回答,但它们都是一般性的,它们无法帮助我修复此错误,因为它来自 SFML 库。如果有人知道如何修复它,请帮助我:)
此处while (window.isOpen)
您正在测试成员函数指针'window.isOpen'不是nullptr
。您的意图是 调用 函数 while (window.isOpen())
。