0
我希望我的函数在单独的线程中运行。我使用Boost库,包括像这样在我main.cpp
:C++线程与Boost库
#include <boost/thread.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
我想线程像这样开头:
boost::thread ethread(Engine::function,info);
// info is an object from the class Engine and i need this in the
// function
我Engine
类是func.h
和功能如下:
void Engine::function(Engine info)
{
//STUFF
boost::this_thread::sleep(boost::posix_time::milliseconds(1));
}
顺便提一下:sleep
函数是否适用于线程?
每次我想要编译它给了我这个错误:
error C3867: "Engine::function": function call missing argument list; use '&Engine::function' to create a pointer to member
我试图使用线程&Engine::function
这个错误出现:
error C2064: term does not evaluate to a function taking 2 arguments
我也试过:
boost::thread ethread(Engine::function,info, _1);
然后出现此错误:
error C2784: "result_traits<R,F>::type boost::_bi::list0::operator [](const boost::_bi::bind_t<R,F,L> &) const"
有人可以帮助我吗?我只想在主线程旁边运行函数。
所以我必须知道的是什么? – NicMaxFen
@NicMaxFen查看更新了解更多详情。从你的代码很难说你应该做什么,请发布更多的代码 – Jeka
没有更多的代码与此相关。现在我得到这个错误: 致命错误LNK1104:文件“libboost_thread-vc100-mt-sgd-1_60.lib”无法打开。 我的代码行我改变了: boost :: thread(boost :: bind(&Engine :: function,&info,info)); – NicMaxFen