Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!olivea!mintaka!bloom-beacon!eru!hagbard!sunic!mcsun!unido!orthogo!basti From: basti@orthogo.UUCP (Sebastian Wangnick) Newsgroups: comp.lang.c++ Subject: friend access to base class members ??? Keywords: friend, inheritance Message-ID: <811@orthogo.UUCP> Date: 12 Oct 90 12:39:29 GMT Distribution: comp Organization: none Lines: 33 I understood from my C++ book that friends have the same access rights as member functions. Now I have some questions on this: Friends must be allowed to access member variables of all their friend class' objects, whereas member functions should only be allowed to access their own member variables? 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? Look at the following code fragment: class Base { protected: int i; }; class D : public Base { int Get1 () { return i; } int Get2 (D d) { return d.i; } friend int Get3 (D d) { return d.i; } }; In my opinion, Get2 should be illegal (accessing hidden member of other object), whereas Get3 should be allowed to do so. But my compiler (Glockenspiel Domain/C++, cfront derivate, 1.2) allows Get2 and flags Get3 with: error: d is protected What is your opinion about that, netters? Sebastian Wangnick (basti@orthogo.uucp)