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