Topic: Valid template friend declaration?


Author: lerdsuwa@users.sourceforge.net (Kriang Lerdsuwanakij)
Date: Tue, 5 Aug 2003 14:39:14 +0000 (UTC)
Raw View
I encounter one interesting case involving member of class template
as friend similar to an example described in paragraph 6 of 14.5.3
in the standard:

  template <class T> struct Y;
  template <class S> class X {
    template <class T> friend void Y<T>::member(); // Referred here
  };
  template <class T> struct Y {
    void member() {                                // Declared here
    }
  };

The difference between this and the one in the standard is that
'Y<T>::member' is not yet declared when it is first referred in the
friend declaration.  I wonder if this is legal.

I am leaning toward viewing it as illegal since 'Y<T>::member'
involves looking up name inside the class template 'Y<T>'.  But another
way to this is treating 'Y<T>::member' as dependent name (despite being
independent of 'S'), making the above code valid.  The wording in the
standard seems to allow this and it is accepted by Comeau compiler.

Any opinion appreciated.

Thank you,

--Kriang

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]