我和朋友正在制作一个简单的多人游戏来练习我们的编码。不幸的是我们遇到了一个问题。 SFML线程系统(不使用std :: thread,因为我的编译器还没有支持它)给了我一个错误。
|| === Build:Debug in Clear Void(编译器:GNU GCC编译器)=== | C:\ Users \ Name \ Documents \ Coding \ SFML work \ Clear_Void \ src \ GameScreen.cpp ||在构造函数' GameScreen :: GameScreen()':|
C:\ Users \ Name \ Documents \ Coding \ SFML work \ Clear_Void \ src \ GameScreen.cpp | 9 | error:ISO C ++禁止获取非限定或带括号的非静态成员函数的地址以形成指向会员功能。说'& GameScreen :: startThread' [-fpermissive] |
C:\ SFML-TDM471x32 \ include \ SFML \ System \ Thread.inl ||实例化' void sf :: priv :: ThreadFunctor :: run()[with T = void(GameScreen :: *)()]':|
C:\ Users \ Name \ Documents \ Coding \ SFML work \ Clear_Void \ src \ GameScreen.cpp | 53 | from this here |
C:\ SFML-TDM471x32 \ include \ SFML \ System \ Thread.inl | 39 |错误:必须使用'。'或者' - > '在'((sf :: priv :: ThreadFunctor )中调用指向成员函数的函数 - >> sf :: priv :: ThreadFunctor :: m_functor(...)' ,例如'(... - > ((sf :: priv :: ThreadFunctor *)this) - > sf :: priv :: ThreadFunctor :: m_functor)(...)&#39 ; |
|| ===构建失败:2个错误,2个警告(0分钟,4秒(秒))=== |
这是我的代码: GameScreen.h
class GameScreen : public Screen
{
public:
GameScreen();
void handleInput(sf::RenderWindow&) override;
void update(sf::RenderWindow&, sf::View&) override;
void render(sf::RenderWindow&) override;
void startThread();
private:
sf::Vector2f moveVal;
Network network;
Events eventManager;
Map m_map;
sf::Thread networkThread;
};
GameScreen.cpp(相关章节)
GameScreen::GameScreen()
: networkThread(&startThread)
{
network.Connect();
}
我检查了SFML线程教程,并根据它们,这应该工作。请帮忙。
答案 0 :(得分:0)
startThread应该是静态的。通常,线程函数不能调用非静态成员函数。