Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!sundance.llnl.gov!jac From: jac@sundance.llnl.gov (James Crotinger) Newsgroups: comp.lang.c++ Subject: Re: friend access to base class members ??? Keywords: friend, inheritance Message-ID: <69720@lll-winken.LLNL.GOV> Date: 13 Oct 90 04:49:37 GMT References: <811@orthogo.UUCP> Sender: usenet@lll-winken.LLNL.GOV Distribution: comp Organization: Lawrence Livermore National Laboratory Lines: 29 In article <811@orthogo.UUCP> basti@orthogo.UUCP (Sebastian Wangnick) writes: >My compiler allows member functions to access member variables >of other objects with the same class, too!? > >More problematically, shouldn't friends be allowed to access >protected: base class members the same way as members can? > I think the first idea, that member functions should only be able to access the private members belonging to *this, would be much too severe a restriction. Objects of the same class by definition know about eachother's representations and should be able to use that knowledge to their advantage, for efficiency reasons, etc. If you want to make sure that an one object doesn't missuse that knowledge, prototype the member functions accordingly (to take const references, etc.). The second point is, I think, a bug in 1.2. Was this fixed in 2.0? > >Sebastian Wangnick (basti@orthogo.uucp) Jim -- ----------------------------------------------------------------------------- James A. Crotinger Lawrence Livermore Nat'l Lab // The above views jac@gandalf.llnl.gov P.O. Box 808; L-630 \\ // are mine and are not (415) 422-0259 Livermore CA 94550 \\/ necessarily those of LLNL.