Templated insertion operators

Dan Gregory dan.gregory@mci.com
Fri Jan 30 20:15:00 GMT 2004


||
I was curious if anyone has noticed problems with templated insertion 
operators for namespaced classes.  Here is a snip of code:

------
namespace ns
{
   template<class T>
   class c
   {
      //...
   }
}

template <class T>
ostream& operator<<(ostream& os, const ns::c<T>& obj);
------

And the error I get is:
======
../../../include/SomeOtherClass.icc:163: no match for 
`_STL::basic_ostream<char,
   _STL::char_traits<char> >& << const ns::c<SomeNamespace::SomeClass>&' 
operator
/usr/local/include/stlport/stl/_ostream.h:70: candidates are:
======

When I move the operator<< into the namespace this problem goes away (so 
there's a workaround), but it doesn't make since that it can't find the 
definition.  As an aside, if I move the declaration into the namespace 
but not the implementation, then I get an ambiguity error between the 2 
versions, so it sees the global one during that run.  This leads me to 
believe that it's a problem with the compiler somehow, I just haven't 
figured out exactly what.||

Unfortunately, I can't get my prototype to fail (it sees the global 
operators just fine (sigh)), but I think that the problem lies in the 
fact that in my real code there are lots of nested templates and 
namespaces.  So I don't have a small piece of code that will fail right 
now... sorry, but I'll keep working on it if anyone thinks this is worth 
pursuing.

Thanks,
Dan



More information about the Gcc-bugs mailing list