3

部分的なテンプレートの特殊化を取得していません。私のクラスは次のようになります。

template<typename tVector, int A>
class DaubechiesWavelet : public AbstractWavelet<tVector> { // line 14
public:
  static inline const tVector waveletCoeff() {
    tVector result( 2*A );
    tVector sc = scalingCoeff();

    for(int i = 0; i < 2*A; ++i) {
      result(i) = pow(-1, i) * sc(2*A - 1 - i);
    }
    return result;
  }

  static inline const tVector& scalingCoeff();
};

template<typename tVector>
inline const tVector& DaubechiesWavelet<tVector, 1>::scalingCoeff() { // line 30
  return tVector({ 1, 1 });
}

エラー gcc 出力は次のとおりです。

line 30: error: invalid use of incomplete type ‘class numerics::wavelets::DaubechiesWavelet<tVector, 1>’
line 14: error: declaration of ‘class numerics::wavelets::DaubechiesWavelet<tVector, 1>’

いくつかの解決策を試しましたが、どれもうまくいきませんでした。誰か私にヒントがありますか?

4

2 に答える 2

3
template<typename tVector>
inline const tVector& DaubechiesWavelet<tVector, 1>::scalingCoeff() { // line 30
  return tVector({ 1, 1 });
}

これは、次のように定義される部分的な特殊化のメンバーの定義です。

template<typename tVector>
class DaubechiesWavelet<tVector, 1> {
  /* ... */
  const tVector& scalingCoeff();
  /* ... */
};

これは、プライマリ テンプレート「DaubechiesWavelet」のメンバー「scalingCoeff」の特殊化ではありません。このような特殊化は、すべての引数の値を渡すために必要ですが、あなたの特殊化は行いません。やりたいことをするために、オーバーロードを使用できます

template<typename tVector, int A>
class DaubechiesWavelet : public AbstractWavelet<tVector> { // line 14
  template<typename T, int I> struct Params { };

public:
  static inline const tVector waveletCoeff() {
    tVector result( 2*A );
    tVector sc = scalingCoeff();

    for(int i = 0; i < 2*A; ++i) {
      result(i) = pow(-1, i) * sc(2*A - 1 - i);
    }
    return result;
  }

  static inline const tVector& scalingCoeff() {
    return scalingCoeffImpl(Params<tVector, A>());
  }

private:
  template<typename tVector1, int A1>
  static inline const tVector& scalingCoeffImpl(Params<tVector1, A1>) {
    /* generic impl ... */
  }

  template<typename tVector1>
  static inline const tVector& scalingCoeffImpl(Params<tVector1, 1>) {
    return tVector({ 1, 1 });
  }
};

使用する初期化構文は C++0x でのみ機能することに注意してください。

于 2010-07-09T20:18:59.040 に答える
3

私はクラスが専門化されているとは思わない。クラスを特殊化し、その内部でメソッドを特殊化する必要があります。

于 2010-07-09T20:15:25.923 に答える