以下は、サードパーティのライブラリで使用したいクラスのコンストラクタです(この関数の変更はオプションではありません)。サードパーティライブラリのメソッドにクラスメンバ関数を渡すにはどうすればよいですか?
template <class Space>
moveset<Space>::moveset(particle<Space> (*pfInit)(rng*),
void (*pfNewMoves)(long, particle<Space> &,rng*),
int (*pfNewMCMC)(long,particle<Space> &,rng*))
はしかし、むしろ単純に3つのグローバル関数を定義するよりも、私は、入力引数が存在しないとして、私は渡すことはできません明らかにされ、様々な追加の情報を知るために各機能を必要とします。この問題をさらに複雑にするために、私はこのmoveetオブジェクトのいくつかの異なるインスタンスを作成したいと思います。それぞれ、同じ関数を使用したいのですが、基礎となる異なるデータにします。
私の考えは
Class DataPlusFunctions {
public:
DataPlusFunctions(Data* dataPtr) { dataPtr_ = dataPtr ;}
smc::particle<cv_state> fInitialise(smc::rng *pRng)
{
// the actual function will be a lot more complicated than this and
// likely to require calling other methods/classes.
// The Data stored in a different class will be changing...which is
// important in relation to the pfNewMoves function.
double value = dataPtr_->value() ;
return smc::particle<cv_state>(value,likelihood(0,value));
}
... same for other required functions
private:
Data* dataPtr_ ;
}
*
Class MainClass {
...
void IK_PFController::initialise()
{
std::vector<DataPlusFunctions> dpfV ;
for (int i = 0 ; i < NSAMPLERS ; i++)
dpfV.push_back(DataPlusFunctions(&data[i])) ;
pSamplers_ = (smc::sampler<cv_state>**)(new void* [NSAMPLERS]) ;
for (int i = 0 ; i < NSAMPLERS ; i++) {
// Normal way of calling function, having defined global functions e.g.
//smc::moveset<cv_state> Moveset(fInitialise, fMove, NULL);
// How to achieve this given my problem ??????????????
//smc::moveset<cv_state> Moveset(&dpfV[i]::fInitialise, &dpfV[i]::fMove, NULL);
pSamplers_[i].SetMoveSet(Moveset);
}
}
}
が許可されており、これらの線に沿って保持クラスのものを作成するのですか?もしそうでなければ、私がムーブセットクラスを変更することができれば、私が試みていることを達成することは可能でしょうか?
'boost :: bind'を見てください。 – Chad
説明したように問題を解決する方法を具体的にどのように説明すればよいでしょうか。 – oracle3001
下記の私の答えを参照してください – Chad