Path: utzoo!utgpu!news-server.csri.toronto.edu!helios.physics.utoronto.ca!ists!yunexus!geac!becker!pantor!richard From: richard@pantor.UUCP (Richard Sargent) Newsgroups: comp.lang.c++ Subject: Access to protected members Message-ID: <59.UUL1.3#5109@pantor.UUCP> Date: 20 Mar 90 14:59:00 GMT Organization: Pansophic Systems Inc, Graphics Product Company Lines: 39 (I apologize if this has been seen before, but I have had no indication that it successfully made its way out into the world.) We have encountered a problem with C++ 2.0, and diligent reading of the manual confirms that we are wrong. :-( I am left with a couple of questions as a result, but first the problem: We have a tree of classes, such as various graphics objects. We want to have some base class members be accessible only to objects from this tree of classes. No problem you say, just use protected. There's the nub: any given object can access its protected base members, but not those of any other object derived from the same tree. (Reference: AT&T Reference Manual, Select Code 307-146, section 11.5 Protected Member Access, page 73) For example, we have a derived class which we want to be able to traverse an array of graphics objects (of which class it is, too). However, this object (and its member functions) cannot access the protected members of the objects in this array. Q1: Why was the language specified with this restriction? I am not a language designer, so I don't understand the decisions that might be obvious to some one is. I certainly don't presume to think that Stroustrup is incorrect, but I do want to understand the ratioanle here. Q2: Given that this restriction is part of the language, how can I work around it? The obvious solution is to make the member in question "public", but then everything has access to it. However, I see no alternatives. Any and all help and explanations welcomed and appreciated. Thanks in advance. Richard Sargent Internet: richard@pantor.UUCP Systems Analyst UUCP: ...!mnetor!becker!pantor!richard