Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!radar!cadillac!dsouza From: dsouza@gwen.cad.mcc.com (Desmond Dsouza) Newsgroups: comp.lang.c++ Subject: Re: protected member functions Message-ID: Date: 15 Mar 91 22:57:54 GMT References: <1991Mar14.215717.28199@asc.slb.com> Sender: news@cadillac.CAD.MCC.COM Distribution: na Organization: MCC CAD Program, Austin, Texas Lines: 27 In-reply-to: wkd@asc.slb.com's message of 14 Mar 91 21:57:17 GMT wkd@asc.slb.com (Bill Duttweiler) asks: >Is it illegal to call a protected member function on an instance other >than 'this'? Consider the following simple example: The derived class has access to inherited protected data members within the context of ANY object OF ITS CLASS, not just "this" (also of further derived classes). See ARM, p. 253 class A { protected: int i; }; class B : public A { public: foo (B* bp, A* ap) { bp->i = 5; // OK ap->i = 5; // ERROR: } }; -- Desmond. -- ------------------------------------------------------------------------------- Desmond D'Souza, MCC CAD Program | ARPA: dsouza@mcc.com | Phone: [512] 338-3324 Box 200195, Austin, TX 78720 | UUCP: {uunet,harvard,gatech,pyramid}!cs.utexas.edu!milano!cadillac!dsouza