From -7443545686863116151 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,2d6fd861b068c0f7 X-Google-Attributes: gid109fba,public X-Google-Thread: f78e5,2d6fd861b068c0f7 X-Google-Attributes: gidf78e5,public X-Google-ArrivalTime: 2001-05-14 04:18:01 PST Path: archiver1.sj.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!dispose.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail From: "Stuart Golodetz" Newsgroups: comp.std.c++,comp.lang.c++ Subject: Re: Inheritance Problems Date: Mon, 14 May 2001 11:17:24 GMT Approved: Fergus Henderson , moderator of comp.std.c++ Message-ID: <3afecb3e$0$12249$cc9e4d1f@news.dial.pipex.com> References: <3AFA4600.7656A271@wit.regiocom.net> <9dh57t$uj$1@uranium.btinternet.com> X-Trace: mail2news.demon.co.uk 989839048 mail2news:9304 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) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6600 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 Lines: 55 Xref: archiver1.sj.google.com comp.std.c++:4709 comp.lang.c++:61617 "Chris Newton" wrote in message news:9dh57t$uj$1@uranium.btinternet.com... > O.Petzold wrote... > > the follwoing code isn't working (with the gcc-2.95.2). > > If I see the inharritance it should ! > > > > class A { > > public: > > void ModifyAnother(A* a2) { > > b = 1; // is working > > a2->b = 1; // woking as well > > } > > protected: > > int b; > > }; > > > > > > class B : public A { > > public: > > void ModifyAnother(A* a2) { > > b = 1; // is working > > a2->b = 1; // not working > > } > > }; > > > > int main() { > > B b; > > } > > > > `int A::b' is protected > > > > Well but, B is derived from A !! > > What says the standard about ? > > Your compiler is correct. You can only access a protected member of A in > B via a pointer or reference to a B object. An A* isn't good enough. > This is from 11.5/1 in the standard if you want to check. > > If you replaced B::ModifyAnother's parameter with (B* a2) instead, it > should then work, because member access is controlled on a per-class and > not per-object basis, so this B can access another B's protected > members. Can a B also access another B's private members? Cos before I read this I worked on the assumption that it was only on a per-object basis... Stuart. --- [ 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.research.att.com/~austern/csc/faq.html ]