From 7760556420902752457
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,5e0145d162a6d1d6
X-Google-Attributes: gidf78e5,public
From: "Walter W. Karas" <wkaras@ibm.net>
Subject: Re: Why is granting friendship to a templ. parameter ill-formed?
Date: 1998/03/11
Message-ID: <3505D38F.723F@ibm.net>#1/1
X-Deja-AN: 333017456
Content-Transfer-Encoding: 7bit
References: <6dop9s$kq6$1@news.utu.fi>
X-Original-Date: Tue, 10 Mar 1998 23:58:07 +0000
X-Notice: should be forwarded in their entirety to postmaster@ibm.net
Content-Type: text/plain; charset=us-ascii
X-Trace: 11 Mar 1998 04:14:31 GMT, 129.37.129.34
Organization: IBM.NET
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUANQa93OEDnX0m9pzZAQGFzwF/eaRTnfjdplMRX07wcJPgmiLYpYQlC/Do KtoFEbd10/xNrfL2a8Ba7H9Dhm5i77GM =OhJU
MIME-Version: 1.0
Reply-To: wkaras@ibm.net
Newsgroups: comp.std.c++


Isn't this one of those chicken-and-egg kind of things?  Consider
this code:

template<class T> class X { ... };

class A { X<A> xa; // error! can only use refs./ptrs to A
};                 // before done declaring A

If the parameter T is a friend of X<T>, wouldn't this lead to a
forward reference like the one above?  I guess you could only
refer to X<A> in non-inline member functions.  That's getting
into some pretty fine distinctions though.


Jaakko =?UNKNOWN-8BIT?Q?J=E4rvi?= wrote:
> 
> Hi,
> 
> Why is this ill-formed?
> 
> template<class T> class X { friend class T; ...
> 
> It is clearly stated in the standard (below a clip from CD2), but what is
> the reason behind it.
> 
> /Jaakko
> 
>  7.1.5.3  Elaborated type specifiers                    [dcl.type.elab]
> ...
> 2 ...
>   If the identifier (my addition: in friend class identifier) resolves to a
> typedef-name or a tem-
>   plate  type-parameter,  the  elaborated-type-specifier  is ill-formed.
>   [Note: this implies that, within a  class  template  with  a  template
>   type-parameter T, the declaration          friend class T;
>   is  ill-formed.  ]
>
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]



