views:

96

answers:

2

Hi,

I'm not getting the partial template specialization. My class looks like this:

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 });
}

The error gcc outputs is:

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>’

I've tried several solutions, but none worked. Anybody has a hint for me?

+4  A: 

I don't see the class specialized. You must specialize the class, and inside it, the method.

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

That's a definition of a member of a partial specialization that would be defined as follows

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

It's not a specialization of the member "scalingCoeff" of the primary template "DaubechiesWavelet". Such a specialization is required to pass the value of all arguments, which your specialization does not do. To do what you want, you can use overloading though

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 });
  }
};

Notice that the initialization syntax you use will only work in C++0x.

Johannes Schaub - litb
cheers!PS: I know about the initialization issue, thanks.
Manuel