0

この問題を克服することは可能ですか:

                class Constants
                { 
                    static Std_ReturnType dtcSitzheizungSchalteMittelkonsoleHlTasterHaengt( UInt8 const value )
                    {
                        return Rte_Call_demSitzheizungSchalteMittelkonsoleHlTasterHaengt_SetEventStatus( value );
                    }

                    static DTCSetter * const DTCSETTER_WITH_NO_DID[SEAT_HEATING_DTCS_COUNT]; //how to use an element of this array as a non type template parameter ?
                };

                template class ButtonStuckPolicy< &Constants::dtcSitzheizungSchalteMittelkonsoleHlTasterHaengt >; //works

C++ 03 で?

一般に、静的配列要素を非型テンプレート パラメータとして渡すことは可能ですか?

ありがとう

4

2 に答える 2

0

私の解決策 - テンプレートの作成:

template <int* arr, int index>
class indexer{
public:
    static inline int* element(){ return arr+index; }
};

それからあなたはただ言う

template <int* arr, int index>
foo{
   // Here use indexer<arr,index>::element();
};

int x[10];
foo<x,0> f;

またはおそらく:

template <typename T>
bar{
   //here use T::element();
};

int x[10];
bar<indexer<x, 0> > b;

それは ほど美しくはありませんfoo<&x[0]>. に特化したすべてのクラスは特化int*を変更する必要があります.

于 2013-07-20T07:23:41.940 に答える