【发布时间】:2016-04-21 08:00:40
【问题描述】:
我希望我的函数在单独的线程中运行。我使用 Boost 库并在我的main.cpp 中包含这样的内容:
#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"
有人可以帮我解决这个问题吗?我只想在主线程旁边运行函数。
【问题讨论】:
标签: c++ multithreading boost