Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!mit-eddie!mit-amt!peter From: peter@mit-amt.MEDIA.MIT.EDU (Peter Schroeder) Newsgroups: comp.lang.c++ Subject: wanting to be a `friend' of a derived class Keywords: derivation,friend,private Message-ID: <714@mit-amt.MEDIA.MIT.EDU> Date: 18 Sep 89 20:41:09 GMT Organization: MIT Media Lab, Cambridge, MA Lines: 62 // I want `another' to have access to the private part of `derived' // which, under cfront 1.2, I can apparently only get by making `another' friend // to the base class. // this program produces: // make test // CC -O -n -o test test.C // CC test.C: // "test.C", line 32: error: a is protected // 1 error // *** Error code 1 // Stop. #include class base{ protected: int a; public: base() : a( 1 ) {} // friend class another; this is what it takes to work. Why? }; class derived : private base{ public: // friend int another::mult(); this is really what I want friend class another; // but I'd settle for this derived() : () {} }; class another{ int b; public: another() : b( 1 ) {} int mult( derived& d ) { return b * d.a; } // I need it here }; main() { another a; derived d; cout << a.mult( d ) << "\n"; } // Notice that this is simplified considerably from the actual problem where I // really need the friend mechanism, rather then a function such as // int derived::geta() { return a; } // which obviously would also solve my problem. // What am I overlooking? // Thanks for your help! // Peter // peter@media-lab.media.mit.edu */