2012-02-20 29 views
1

我正在创建C++游戏服务器。服务器创建了许多对象monster,并且每个monster都应该有其具有特定功能的线程。错误C2064:术语不评估为一个采用0参数的函数thread.hpp(60)

我得到错误:

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 

回答

5

mob_engine是一个非静态成员函数,所以它有一个隐含的论据。通过写

boost::thread make_thread(boost::bind(&monster::mob_engine, this)); 

根据这个类似的问题boost:thread - compiler error你甚至能避免使用绑定

试试这个

boost::thread make_thread(&monster::mob_engine, this); 

此外,你可能会想声明提振: :线程成员变量保持对线程的引用。

相关问题