From 436212168129067597 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,7961205d5764d0b X-Google-Attributes: gidf78e5,public From: Biju Thomas Subject: Re: A suspect bug in Visual C++ Date: 1998/11/29 Message-ID: <3661A689.4C80EFFE@ibm.net>#1/1 X-Deja-AN: 416875214 X-NNTP-Posting-Host: 32.100.143.75 Content-Transfer-Encoding: 7bit Approved: stephen.clamage@sun.com (comp.std.c++) References: <8767c1s375.fsf@pot.cnuce.cnr.it> X-Notice: should be reported to postmaster@ibm.net Content-Type: text/plain; charset=us-ascii X-Complaints-To: postmaster@ibm.net X-Trace: 29 Nov 1998 19:57:46 GMT, 32.100.143.75 Organization: IBM.NET Mime-Version: 1.0 Reply-To: bijuthom@ibm.net Newsgroups: comp.std.c++ Originator: clamage@taumet Francis Glassborow wrote: > > I find this an interesting question. To what is f() being granted > access? > The private interface of class B. But this is not the same as the > private interface of class A. > > I think you have to declare friend void f() in both A and B. Can anyone > quote the Standard to justify accepting the code as written? Quote from 11.4/2: "Declaring a class to be a friend implies that the names of private and protected members from the class granting friendship can be accessed in declarations of members of the befriended class." There is an example too, which elaborates this point in the case of nested classes: class A { class B { }; friend class X; }; class X { A::B mx; // ok: A::B used to declare member of X }; This talks about befriended classes only. But, I think, it extends to befriended functions too. May be, the wording of the above clause has to be changed so that it is made explicit in the case of friend functions too. Without such a feature, declaring friends of nested classes becomes a nightmare, as all the containing classes have to have the same friend declaration. And, having such a friend declaration in the containing class is dangerous, as it will expose the containing class the friend class/function unnecessarily. > > In article <8767c1s375.fsf@pot.cnuce.cnr.it>, Francesco Potorti` > writes > > >Hi, this is observed behaviour on VC++ 4.0, 5.0, 6.0. The following > >snippet of code compiles without errors under egcs (as it should, in my > >opinion), while it generates an error when compiled by VC++. > > >--------------------------- > >class A { > > class B { > > struct C {}; > > friend void f(); > > }; > >}; > >void f() { > > A::B::C *p; > >} > >--------------------------- > >--> baco_VC.cpp(9) : error C2248: 'C' : > > cannot access private struct declared in class 'A::B' Regards, Biju Thomas [ 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 ]