-2

I have typedefs defined inside a template class:

template <class T>
class ROIAlg{
  public:
    typedef std::vector<T> Waveform;
    typedef typename Waveform::const_iterator Tick;
    typedef std::pair<Tick, Tick> Region;
  //etc.
};

and another class that uses them

template <class T>
class WaveformPropertiesAlg{
  public:
    WaveformPropertiesAlg();
  private:
    typename ROIAlg<T>::Region fCPR;
  //etc.
};

The implementation of the constructor of WaveformPropertiesAlg:

template <class T>
WaveformPropertiesAlg<T>::WaveformPropertiesAlg():
  fCPR(ROIAlg<T>::Tick(), ROIAlg<T>::Tick()) {
  //etc
}

Another piece of code attempts to construct a WaveformPropertiesAlg<short int> but compilation fails:

In instantiation of ‘WaveformPropertiesAlg<T>::WaveformPropertiesAlg() [with T = short int]’:
RawDigitAndWireComparisonAlg.cxx:13:77:   required from here
WaveformPropertiesAlg.h:30:51: error: dependent-name ‘ROIAlg<T>::Tick’ is parsed as a non-type, but instantiation yields a type
   fCPR(ROIAlg<T>::Tick(),ROIAlg<T>::Tick())
                       ^
WaveformPropertiesAlg.h:30:51: note: say ‘typename ROIAlg<T>::Tick’ if a type is meant

I don't think a type is meant here because I'm calling the constructor of Tick. How can I do this?

  • The compiler needs to be told that `ROIAlg::Tick` is a typename. – R Sahu Feb 06 '15 at 23:26
  • 1
    How often (per day) do we get this on SO? Why don't people read their compiler's error message but just discard them? – Walter Feb 06 '15 at 23:31

1 Answers1

1

typedef typename Waveform::const_iterator Tick; << That is a type, hence you need typename as the compiler tells you:

fCPR(typename ROIAlg<T>::Tick(), typename ROIAlg<T>::Tick())

The case in which you would not need typename would be if Tick were something else, such as a function:

template <class T>
class ROIAlg{
  public:
    static T Tick();
};
Dark Falcon
  • 43,592
  • 5
  • 83
  • 98