1

odeint のステッパー クラスでいくつかの作業を実行できるテンプレート化されたクラスがあり、それをステッパーのカテゴリごとに特定の (異なる) 作業にしたいと考えています。

/// header file ///

template<class Stepper>
class foo {
    typedef typename boost::numeric::odeint::unwrap_reference< Stepper >::type::stepper_category stepper_category;
    void do_work(double param);
    // specific functions for various stepper types
    void do_specific_work(double param, stepper_category);
}

/// cpp file ///
template<class Stepper>
void foo<Stepper>::do_work(double param)
{
    do_specific_work(param, stepper_category());
}

// actual implementation of work for any stepper (i.e. exposing the basic functionality of stepper_tag)
template<class Stepper>
void foo<Stepper>::do_specific_work(double param, boost::numeric::odeint::stepper_tag)
{ ... }

// actual implementation of work for dense output stepper (i.e. exposing the functionality of dense_output_stepper_tag)
template<class Stepper>
void foo<Stepper>::do_specific_work(double param, boost::numeric::odeint::dense_output_stepper_tag)
{ ... }

問題は、次のコンパイラ エラーが発生することです。

error C2244: 'foo<Stepper>::do_specific_work' : unable to match function definition to an existing declaration`

などのメソッドが実装されているのと同じ方法で実行しようとしましたがintegrate_adaptive、私の場合との違いは、それらがスタンドアロン関数 (クラスのメンバーではない) であり、前方宣言を必要としないことです。必要なものを達成するためにコードを変更する方法は? 前もって感謝します!

4

2 に答える 2

1
// actual implementation of work for any stepper (i.e. exposing the basic functionality of stepper_tag)

このメソッドを任意の stapper_tag で機能させたい場合は、関数テンプレートを使用する必要があります。

template<class StepperTag>
void do_specific_work(double param, StepperTag stepper);

そして実装:

template<class Stepper>
template<class StepperTag>
void foo<Stepper>::do_specific_work(double param, StepperTag stepper)
{ ... }

template<class Stepper>
void foo<Stepper>::do_specific_work(double param, boost::numeric::odeint::dense_output_stepper_tag stepper)
{ ... }
于 2013-12-12T22:31:24.833 に答える
1

特定のカテゴリに明示的なオーバーロードを提供する必要があります。

template<class Stepper>
class foo {
    typedef typename boost::numeric::odeint::unwrap_reference< Stepper >::type::stepper_category stepper_category;

    // ...


    void do_specific_work(double param, stepper_tag );
    void do_specific_work(double param, dense_output_stepper_tag );
};

template< class Stepper >
void foo< Stepper >::do_specific_work( double param , stepper_tag )  { ... };

template< class Stepper >
void foo< Stepper >::do_specific_work( double param , dense_output_stepper_tag )  { ... };

1 つの宣言 do_specific_work( double param , stepper_category ) といくつかの定義があります。あなたのプロトタイプは現在、定義と一致しません。

于 2013-12-12T22:18:33.930 に答える