Re: template friend operator and template class: problem

From: Alwyn (dt015a1979_at_mac.com.invalid)
Date: 08/25/04


Date: Wed, 25 Aug 2004 14:53:59 +0100

In article <412c9365$0$20797$a729d347@news.telepac.pt>, Rui Maciel
<rui_maciel@mail.com> wrote:

> Alwyn wrote:
> > In article <412baa96$0$1799$a729d347@news.telepac.pt>, Rui Maciel
> > <rui_maciel@mail.com> wrote:
> ><snip>
> >>template <typename U, unsigned int l1, unsigned int l2>
> >>bool operator==(const A<U, l1> &lhs, const A<U, l2> &rhs);
> >
> >
> > Do you need these declarations? I don't believe they contribute
> > anything to the code as it stands.
> >
> >
> >>template <typename T, int lines>
> >>class A {
> >> public:
> >> //snip
> >> template<typename U, int l1, int l2>
> >> friend bool operator==<U, l1, l2>(const A<U, l1> &lhs, const A<U, l2>
> >>&rhs); // line pointed by the error message
> >
> >
> > Shouldn't that be:
> > friend bool operator==(const A<U, l1> &lhs, const A<U, l2> &rhs);
> > ?
>
> You are absolutely right. The thing is, I started doing this template
> friend operator from a declaration of a friend template operator that
> used the template class parameters, which apparently needs all those
> forward declarations to work.

So it compiles for you now? I was afraid it might be a compiler
problem; not all of them support template friends yet.

Alwyn



Relevant Pages

  • Re: Templated friends
    ... > You can make a template friend. ... > declarations, so if you can declare it, you can make a friend out of ...
    (comp.lang.cpp)
  • Re: Circular Class Template Friendship
    ... > My issue is the syntax of declaring a friend class within ... > which the string is a fixed width that is specialized. ... it is still possible to have Name_Id_Table template ... the friend class declaration. ...
    (comp.lang.cpp)
  • Re: Class templates and friend function templates
    ... > It never occurred to me that the friend declaration could be an overload. ... > template ... I suspect the online version uses an EDG option to "instantiate ...
    (microsoft.public.vc.language)
  • Re: Template friendship to nested template class
    ... friend struct INNER; ... Probably you are missing an EXTRA template to declare ... I think it's because the name referred to in a 'friend' declaration is looked up to exist at the namespace scope. ...
    (microsoft.public.vc.language)
  • Re: Template friendship to nested template class
    ... template ... friend struct INNER; ... Both VC and gcc are happy with this code, but the intel compiler is ...
    (microsoft.public.vc.language)