ダイナミックディスパッチを避けるために、バートンとナックマンのトリックを使ってクラスを実装しようとしています。私はC + +のエキスパートではありませんが、基本的なトリックは私のために働いています。しかし、私は今、2番目の派生クラスをテンプレート化する必要がある場合があります。これは問題を引き起こすようです。私のコードの概要は次のとおりです。テンプレート付きバートンとナックマントリックの問題
// Generic step class
template<class DerivedStepType>
class Step {
public:
DerivedStepType& as_derived() {
return static_cast<DerivedStepType&>(*this);
}
void DoStep() {
return as_derived.DoStep();
}
};
// Gibbs step
template<class DerivedParameterType> // THIS IS THE PROBLEM
class GibbsStep : public Step<GibbsStep> {
public:
GibbsStep(DerivedParameterType new_parameter) {
}
void DoStep() {
}
};
問題がtemplate<class DerivedParameterType>
と(バートンとNackmanトリックから)以下<GibbsStep>
です。 G ++ V 4.01(OSX)を使用して、私は次のエラーを取得する:
./src/mcmc.h:247: error: type/value mismatch at argument 1
in template parameter list for 'template<class DerivedStepType> class Step'
./src/mcmc.h:247: error: expected a type, got 'GibbsStep'
すべてがドロップtemplate<class DerivedParameterType>
場合は罰金コンパイルしdouble
、たとえば、とDerivedParameterType
を交換してください。
アイデア?
小さな修正:GibbsStepはクラステンプレートではなく、テンプレートクラスです;) – ovanes