この質問に続いて
クラスメンバー関数をサードパーティライブラリのメソッドに渡す方法は?
簡単に要約すると、関数へのポインターを、サードパーティ ライブラリの moveset というクラスのコンストラクターに、次の定義で渡す必要があります。
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
どんな助けでも大歓迎です