3
How to pass class member functions to a method in a 3rd party library?
快速回顧一下是我需要的指針傳遞給函數稱爲moveset在第3類的構造函數繼黨庫的
template <class Space>
moveset<Space>::moveset(particle<Space> (*pfInit)(rng*),
void (*pfNewMoves)(long, particle<Space> &,rng*),
int (*pfNewMCMC)(long,particle<Space> &,rng*))
庫提供的示例定義是簡單地定義pfInit等全局函數,讓他們打電話F,G和H。然後從控制器類中調用smc :: moveset Moveset(f,g,h);
我試圖用boost:bind來實現這個建議。不幸的是,我正在努力讓這個工作。
class IK_PFWrapper
{
public:
IK_PFWrapper(Skeleton* skeleton, PFSettings* pfSettings) ;
smc::particle<cv_state> fInitialise(smc::rng *pRng);
...
} ;
在控制器類
IK_PFWrapper testWrapper (skeleton_,pfSettings_);
boost::function<smc::particle<cv_state> (smc::rng *)> f = boost::bind(&IK_PFWrapper::fInitialise, &testWrapper,_1) ;
// the 2nd and 3rd argument will be eventually be defined in the same manner as the 1st
smc::moveset<cv_state> Moveset(f, NULL, NULL);
所得編譯器錯誤是
,
Algorithms\IK_PFController.cpp(88): error C2664: 'smc::moveset<Space>::moveset(smc::particle<Space> (__cdecl *)(smc::rng *),void (__cdecl *)(long,smc::particle<Space> &,smc::rng *),int (__cdecl *)(long,smc::particle<Space> &,smc::rng *))' : cannot convert parameter 1 from 'boost::function<Signature>' to 'smc::particle<Space> (__cdecl *)(smc::rng *)'
with
[
Space=cv_state
]
and
[
Signature=smc::particle<cv_state> (smc::rng *)
]
and
[
Space=cv_state
]
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
十分讚賞
閱讀你以前的[問題](http://stackoverflow.com/questions/9997299/how-to-pass-class-member-functions-to-a-method-in-a-3rd-party-library)我不確定上述是否真正解決了原來的問題。我已經提供了關於原始問題的更多細節。 – Zero 2012-04-11 22:04:35