c++ - 在 sf::thread 中运行同一个类的成员函数
问题描述
简单而简短:第 4 行有什么问题?我不能用同一类的 0 个参数调用 void。
#include "Game.h"
Game::Game(int width, int height, std::string title) {
sf::RenderWindow* window = new sf::RenderWindow(sf::VideoMode(width, height), title, sf::Style::Titlebar | sf::Style::Close);
gameThread = new sf::Thread(&Game::run, window);
window->setActive(false);
sf::Event event;
gameThread->launch();
while (window->pollEvent(event)) {
if (event.type = sf::Event::Closed)
window->close();
delete &event;
}
gameThread->wait();
}
Game::~Game() {
delete &clock;
delete &window;
delete &gameThread;
clock = nullptr;
window = nullptr;
gameThread = nullptr;
}
void Game::run(sf::RenderWindow* window) {
while (window->isOpen()) {
window->clear();
window->display();
}
}
在 sf::Thread 类的文档中,所有内容都在示例中进行了解释,但并不是我要做什么。Visual Studio 只是说没有合适的默认构造函数可用。
解决方案
推荐阅读
- python - VS Code 调试导致 Python 子进程挂起
- python - 如何将一列拆分为三列?
- python - Python + Pandas:无需迭代的 DataFrame 计算
- android - 过渡管理器延迟过渡不适用于android中的多个视图
- python - 使用斐波那契:暂停执行并从它停止的地方开始的 Python 函数
- reactjs - 异步函数返回承诺对象而不是返回布尔值(reactjs Hooks)
- react-native - 如何在登录屏幕中隐藏底部标签导航?
- r - 如何从 Landsat 图像中提取值并在 R 中绘制不同材料的光谱剖面
- kubernetes - 使用其他属性更新 helm 图表
- javascript - Wordpress 自定义 JS 位置