編譯使用線程的程序時出現錯誤。這是導致問題的部分。如果有人告訴我是否以正確的方式調用線程函數,那將會很好。如何從main()調用線程成員函數
在main.cpp中:
int main()
{
WishList w;
boost::thread thrd(&w.show_list);
thrd.join();
}
在another_file.cpp:
class WishList{
public:
void show_list();
}
void WishList::show_list(){
.
.
.
.
}
我收到以下錯誤
error: ISO C++ forbids taking the address of a bound member function to form a pointer to member function. Say ‘&WishList::show_list’
/home/sharatds/Downloads/boost_1_46_1/boost/thread/detail/thread.hpp: In member function ‘void boost::detail::thread_data<F>::run() [with F = void (WishList::*)()]’:
/home/sharatds/Downloads/boost_1_46_1/boost/thread/detail/thread.hpp:61:17: error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘((boost::detail::thread_data<void (WishList::*)()>*)this)->boost::detail::thread_data<void (WishList::*)()>::f (...)’, e.g. ‘(... ->* ((boost::detail::thread_data<void (WishList::*)()>*)this)->boost::detail::thread_data<void (WishList::*)()>::f) (...)’
編輯:安裝Boost庫爲遇到問題線程。應儘快嘗試這個,因爲它的工作原理
通過「main.cpp():」你的意思是? 「main.cpp中的int main()」? – Johnsyweb
是的。沒錯 –