我正在嘗試使用boost :: bind傳遞函數指針。將綁定回調函數指針作爲參數
void
Class::ThreadFunction(Type(*callbackFunc)(message_type::ptr&))
{
}
boost::shared_ptr<boost::thread>
Class::Init(Type(*callbackFunc)(message_type::ptr&))
{
return boost::shared_ptr<boost::thread> (
new boost::thread(boost::bind(&Class::ThreadFunction, callbackFunc))
);
}
我收到以下錯誤:
1>C:\dev\sapphire\boost_1_46_1\boost/bind/mem_fn.hpp(362) : warning C4180: qualifier applied to function type has no meaning; ignored
1>C:\dev\sapphire\boost_1_46_1\boost/bind/mem_fn.hpp(333) : error C2296: '->*' : illegal, left operand has type 'Type (__cdecl **)(message_type::ptr &)'
不過,我能換到下面,它工作正常:
void
ThreadFunction(Type(*callbackFunc)(message_type::ptr&))
{
}
boost::shared_ptr<boost::thread>
Class::Init(Type(*callbackFunc)(message_type::ptr&))
{
return boost::shared_ptr<boost::thread> (
new boost::thread(boost::bind(&ThreadFunction, callbackFunc))
);
}
爲什麼我得到,如果我這些錯誤在Class類中聲明該方法?
+1,我忘記提及使用成員函數的替代方案。 – Anthony