[bug] Template friends, namespace and instantiation

Lavoie Philippe lavoie@zeus.genie.uottawa.ca
Wed Dec 9 07:40:00 GMT 1998


Martin von Loewis writes:
 > > I can't get this to work. It seems that there is a problem when
 > > overloading a friend function which is inside a namespace.
 > [...]
 > >  namespace Test {
 > >   template <class T> void resizeG(Vector<T>&, int ) { cout << "A" ;}
 > > 
 > >   template <>
 > >   void resizeG(Vector<Point<float,3> >& , int ) { cout << "B" ; }
 > >  }
 > > 
 > >  using namespace Test ; 
 > >  template void resizeG<Point<float,3> >(Vector<Point<float,3> >& , int ) ;
 > 
 > You did not mention what compiler you are using. I get (with
 > egcs-2.92.21):
 > 

Sorry about that, it's with egcs 1.1.1

 > nameFriend.cc:13: explicit instantiation of `void resizeG<Point<float,3>>(class Test::Vector<Point<float,3> > &, int)' after
 > nameFriend.cc:8: explicit specialization here
 > 
 > which is different from the message you get.
 > 
 > I believe your code is wrong. First, you declare a specialization. You
 > cannot have an explicit instantiation after you had the specialization.
 > 

With -fno-implicit-template how do you do it then?

 > What's more, there is a requirement that these things happen in the
 > namespace where the template was declared. I'm not sure whether this
 > restriction applies to specializations only, or to instantiations as
 > well.

Well if I remove line 13, then at link time it doesn't find
resizeG(Vector<float,3> >,int).

And this is a case where, it worked under 1.1 so what changed ? 

Thanks for any more information.

Phil



More information about the Gcc-bugs mailing list