From -1909271362504570201 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,ab7a787617b58a3a X-Google-Attributes: gidf78e5,public X-Google-ArrivalTime: 2002-05-31 16:59:02 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!skynet.be!skynet.be!kibo.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail From: "Eigil Hysv�r" Newsgroups: comp.std.c++ Subject: Re: friend of private nested class - is this legal C++? Date: Fri, 31 May 2002 23:58:35 GMT Organization: BaneTele Nett Public Access Approved: Fergus Henderson , moderator of comp.std.c++ Message-ID: References: <3CF277C1.B98D3211@itgssi.com> X-Trace: mail2news.demon.co.uk 1022889519 mail2news:27187 mail2news mail2news.demon.co.uk X-Complaints-To: abuse@demon.net X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov) User-Agent: Xnews/4.06.22 NNTP-Posting-Date: Fri, 31 May 2002 11:56:10 CEST Lines: 38 Xref: archiver1.google.com comp.std.c++:11758 Joseph Heled wrote in news:3CF277C1.B98D3211@itgssi.com: > > Is this legal or not? g++ 3.1 says not, but I can't see why. > I would appreciate a comment from a "language lawyer" ... > > ---------------------------------------------- > class A { > private: > class B { > friend void f(B&); > }; > }; > > void > f(A::B&) {} > ---------------------------------------------- > > ================================================= > g++ -Wall -c t3.cc > t3.cc: In function `void f(A::B&)': > t3.cc:4: `class A::B' is private > t3.cc:11: within this context > ================================================= > Both your classes is legal code. Since B is private, only A is able to create an object of B and thus is the only one able to call 'f(A::B&)'. It looks like you're calling 'f' from the global scope in your example - how did it get access to a 'B'-object? --- [ 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 ]