SFML:没有与Thread()匹配的函数
SFML: no matching function to Thread()
我尝试在我的游戏中使用SFML线程,但我遇到了一个问题。我的代码:
void MyGame::endGame()
{
sf::Thread thread(&PuzzleGame::endThread);
thread.Launch();
}
void MyGame::endThread()
{
}
结果是:
../src/MyGame.cpp: In member function ‘void MyGame::endGame()’:
../src/MyGame.cpp:186:51: error: no matching function for call to ‘sf::Thread::Thread(void (MyGame::*)())’
sf::Thread thread(&MyGame::endThread);
^
什么是问题?
编辑我使用SFML 1.6
thread.launch();
注意小写
如果你感兴趣,这里是文档:
http://www.sfml-dev.org/tutorials/2.0/system-thread.php如果你想传递一个类函数,你还需要传递你想调用它的对象:
void MyGame::endGame()
{
sf::Thread thread(&MyGame::endThread, this);
thread.launch();
}
void MyGame::endThread()
{
}
或者您可以使用静态类方法:
void MyGame::endGame()
{
sf::Thread thread(&MyGame::endThread);
thread.launch();
}
static void MyGame::endThread()
{
}
请阅读SFML线程的完整文档。创建线程的局部变量是没有帮助的。当超出作用域并且您希望线程运行时,它将被销毁,而不是被删除。
我看到你正在使用旧的SFML 1.6。请仔细阅读教程。在旧版本中,您只能使用上述两个选项中的第二个选项。您可能希望尽快切换到2.0或2.1。
相关文章:
- 对带有唯一指针的 std::thread 使用类成员函数时出现编译错误
- 将模板(没有规范)传递给 std::thread() 会出现错误:<未解析的重载函数类型>匹配错误
- 在没有复制构造函数的对象的成员函数中启动 std::thread
- 无法将参数传递给 boost::thread 构造函数
- CLang:在 std::thread 中运行函数会导致结构创建BAD_ACCESS
- 如何在 UWP C++/CX 中对象的成员函数中使用 std::thread
- 使用 std::thread & std::bind 在成员函数中启动线程
- 错误:调用 std::thread 没有匹配函数
- 有什么理由C++ 11+ std::mutex 应该声明为全局变量,而不是作为函数参数传递到 std::thread 中
- std::thread从函数启动,无需等待线程完成
- 使用 boost::thread 运行函子,但析构函数被错误地调用
- 睡眠影响 std::thread 调用哪个虚拟成员函数?
- 如何在不接触函数本身的情况下暂停和恢复 C++11 std::thread 的功能
- C++ - 在 std::thread 中调用重载函数时编译失败
- 子类化 std::thread:构造器中可变参数模板函数的问题
- 如果容器不是调用函数中的引用,则使用 std::thread 传递对迭代器的引用将失败
- 标准库中是否有与 std::thread 的构造函数语义匹配的类型擦除函数包装器?
- 将回调函数中对对象的引用传递给 std::thread
- thread.detach() 函数的左值何时会超出以下代码的范围
- VSCod 中的C++:错误:没有用于初始化'std::thread'的匹配构造函数