This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: A simple sample code involving templates, friends and lookup


On Jan 17, 2008 2:12 PM, Dragan Milenkovic <dragan@plusplus.co.yu> wrote:
> Richard Guenther wrote:
> [snip]
> >> template <typename T>
> >> struct Foo
> >> {
> >>      template <typename Z>
> >>      friend void func(const Foo &);
> >> };
> >>
> >> void check(const Foo<int> & x)
> >> {
> >>      // Foo<int> weird;  // uncomment this line and all works
> >>
> >>      func<int>(x);    // <-- ERROR
> >> }
> >>
> >>
> >> Tested with gcc 4.0 - 4.3, and all behave the same:
> >>
> >> "error: 'func' was not declared in this scope"
> >>
> >> but it works if you uncomment the weird line.
> >
> > Actually even with the weird line the program is invalid.  What are
> > you trying to do? ;)
> >
> > Richard.
>
> Ok... afaik, that func should be defined on that very place where it is
> declared as friend. But could you please elaborate why it is invalid,
> since you made me start questioning my C++ knowledge... :-D

How should name-lookup find func?

Richard.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]