带有模板模板参数的'operator <<'的模糊重载

Sis*_*dám 5 c++ templates operator-overloading

我正在尝试创建一个模板类,其中一个人可以将类使用的(STL)容器定义为模板参数.所以我做了以下事情:

template <typename T = float,
          template < class, class > class Container = std::vector,
          class Alloc = typename std::vector < Spectrum < T > >::allocator_type>
class Spectrogram;
Run Code Online (Sandbox Code Playgroud)

我的问题是,当我为流操作符定义我的重载时

// Definition inside the 'public' part of the 'Spectrogram' class
template <typename Type,
          template < class, class > class C,
          class A>
friend std::ostream & operator << ( std::ostream &, const Spectrogram < Type, C, A > & );

// Implementation
template <typename Type,
          template < class, class > class C,
          class A>
std::ostream & operator << ( std::ostream & o, const Spectrogram < Type, C, A > & s )
{
   // Transparent implementation
   return o;
}
Run Code Online (Sandbox Code Playgroud)

然后创建一些测试代码

Spectrogram < float > spectrogram;
// Fill the spectrogram etc. -- codepart omitted
std::cout << spectrogram;
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Ambiguous overload for 'operator<<'
Run Code Online (Sandbox Code Playgroud)

我可能做错了什么,但我无法理解.

谢谢你的帮助,Ádám

PS引用的类具有以下定义:

// Spectrum
template < typename T = float, class Container = std::vector < T > > class Spectrum {
public:
   typedef T ( * WindowFunction ) ( const T & );
   typename Container::const_iterator begin ( void ) const;
   typename Container::const_iterator end ( void ) const;
   typename Container::const_reverse_iterator rbegin ( void ) const;
   typename Container::const_reverse_iterator rend ( void ) const;
   WindowFunction getWindowFunction ( void ) const;
   typename Container::size_type getWindowSize ( void ) const;
   typename Container::size_type getFFTSize ( void ) const;
   void setWindowFunction ( const WindowFunction & );
   void setFFTSize ( const typename Container::size_type & );
   template < class InputIterator > void import ( const InputIterator &, const InputIterator & );
   template < typename Type, class C > friend std::ostream & operator << ( std::ostream &, const Spectrum < Type, C > & );
protected:
   WindowFunction windowFunction;
   typename Container::size_type windowSize;
   Container spectrum;
   void clear ( void );
};

// Spectrogram
template < typename T = float, template < class, class > class Container = std::vector, class Alloc = typename std::vector < Spectrum < T > >::allocator_type > class Spectrogram {
public:
   typedef typename Container < Spectrum < T >, Alloc >::const_iterator Iterator;
   typedef typename Container < Spectrum < T >, Alloc >::const_reverse_iterator ReverseIterator;
   typedef typename Container < Spectrum < T >, Alloc >::size_type size_type;
   Iterator begin ( void ) const;
   Iterator end ( void ) const;
   ReverseIterator rbegin ( void ) const;
   ReverseIterator rend ( void ) const;
   size_type size ( void ) const;
   bool empty ( void ) const;
   WindowTypes getWindowType ( void ) const;
   double getHopFactor ( void ) const;
   unsigned long getWindowSize ( void ) const;
   unsigned short getOversamplingFactor ( void ) const;
   unsigned long getHopSize ( void ) const;
   void setWindowType ( const WindowTypes & );
   void setHopFactor ( const double & );
   void setWindowSize ( const unsigned long & );
   void setOversamplingFactor ( const unsigned short & );
   template < class InputIterator > void import ( const InputIterator &, const InputIterator & );
   template < typename Type, template < class, class > class C, class A > friend std::ostream & operator << ( std::ostream &, const Spectrogram < Type, C, A > & );
protected:
   Container < Spectrum < T >, Alloc > spectrogram;
   double hopFactor;
   unsigned long windowSize;
   unsigned short oversamplingFactor;
   WindowTypes windowType;
};
Run Code Online (Sandbox Code Playgroud)

我正在使用GCC 4.2和XCode 4.0.2.

n. *_* m. 1

在 GCC 4.3 和 4.4 下编译,但 4.1 给出类似于您所描述的错误。一定是 GCC 的错误。