From -3215207605844243365 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-12 08:30:02 PST Path: archiver1.sj.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!colt.net!dispose.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail From: "Chris Newton" Newsgroups: comp.std.c++,comp.lang.c++ Subject: Re: Inheritance Problems Date: Sat, 12 May 2001 15:28:04 GMT Organization: BT Internet Approved: Fergus Henderson , moderator of comp.std.c++ Message-ID: <9dh57t$uj$1@uranium.btinternet.com> References: <3AFA4600.7656A271@wit.regiocom.net> X-Trace: mail2news.demon.co.uk 989681370 mail2news:21023 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.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 Lines: 51 Xref: archiver1.sj.google.com comp.std.c++:4666 comp.lang.c++:61348 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. Hope that helps, Chris --- [ 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 ]