我正在创建c++游戏服务器。服务器创建许多对象monster
,每个monster
都应具有其具有特定功能的线程。
我收到错误消息:
error C2064: term does not evaluate to a function taking 0 arguments
thread.hpp(60) : while compiling class template member function 'void
boost::detail::thread_data<F>::run(void)'
monster.cpp
:#include "monster.h"
monster::monster(string temp_mob_name)
{
//New login monster
mob_name = temp_mob_name;
x=rand() % 1000;
y=rand() % 1000;
boost::thread make_thread(&monster::mob_engine);
}
monster::~monster()
{
//Destructor
}
void monster::mob_engine()
{
while(true)
{
Sleep(100);
cout<< "Monster name"<<mob_name<<endl;
}
}
monster.h
:#ifndef _H_MONSTER_
#define _H_MONSTER_
//Additional include dependancies
#include <iostream>
#include <string>
#include "boost/thread.hpp"
using namespace std;
class monster
{
public:
//Functions
monster(string temp_mob_name);
~monster();
//Custom defined functions
void mob_engine();
int x;
int y;
};
//Include protection
#endif
最佳答案
mob_engine是一个非静态成员函数,因此它具有隐式this参数。
试试这个:
boost::thread make_thread(boost::bind(&monster::mob_engine, this));
根据这个类似的问题boost:thread - compiler error,您甚至可以通过简单地编写以下代码来避免使用bind:
boost::thread make_thread(&monster::mob_engine, this);
另外,您可能需要声明一个boost::thread成员变量来保留对该线程的引用。
关于multithreading - 错误C2064 : term does not evaluate to a function taking 0 arguments thread. hpp(60),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9361244/