From -2422717720121777687
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,5e0145d162a6d1d6
X-Google-Attributes: gidf78e5,public
From: Srinivas Vobilisetti <srv@cs.wayne.edu>
Subject: Re: Why is granting friendship to a templ. parameter ill-formed?
Date: 1998/03/07
Message-ID: <35005B2A.7410@cs.wayne.edu>#1/1
X-Deja-AN: 331584274
Content-Transfer-Encoding: 7bit
References: <6dop9s$kq6$1@news.utu.fi>
X-Original-Date: Fri, 06 Mar 1998 13:23:06 -0700
X-Authentication-Warning: crchh14.us.nortel.com: news set sender to  srv@cs.wayne.edu using -f
Content-Type: text/plain; charset=us-ascii
Organization: Bell Northern Research
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUANQCpGOEDnX0m9pzZAQGCigF9HMiaYokYCdihkycAa5QNWYbQUv2jH7I0 J1xgm6QFBtbJbQgo3fIgdTajacL4nLQD =6PqV
Mime-Version: 1.0
Newsgroups: comp.std.c++


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.  ]
> 

To prevent back door access to template class's private members. If you
give friendship based on the template parameter, then any class can get
access to the template private members thru back door (by creating an
instance of the template with its type as parameter). Taking your
example, my class Y can get access to private members of your template
class X by creating an instance of X<Y>.

Srinivas
---
[ 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              ]



