Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!att!cbnewsl!dog From: dog@cbnewsl.ATT.COM (edward.n.schiebel) Newsgroups: comp.lang.c++ Subject: Re: Private base class Message-ID: <3594@cbnewsl.ATT.COM> Date: 11 Jan 90 12:59:27 GMT References: <4604@helios.ee.lbl.gov> Organization: AT&T Bell Laboratories Lines: 65 From article <4604@helios.ee.lbl.gov>, by beard@ux1.lbl.gov (Patrick C Beard): > In article <1533@castle.ed.ac.uk> sam@lfcs.ed.ac.uk (S. Manoharan) writes: > # > #Yet another What's-wrong-with-my-code question: > # > # (deleted example code) > # > #Compiling this with CC (cfront version 1.2.1) gives the following > #errors: > #CC test.c: > #"test.c", line 18: error: a is from private base class > #"test.c", line 19: error: f is from private base class > #2 errors > > As it should, you have inherited the base class privately. In other > words, all members, public, protected, or private, are inaccessible > to the derived class. Not exactly. By default the members are inaccessible to USERS of the derived class. Member functions of the derived itself retains access to base's public and protected. By specifying base::a and base::f in derived's public section, these members of base have now been declared as public to derived and accessible to users of derivec. The given example code does compile correctly using cfront 2.00. > The fix is to declare derived like so: > > derived : public base {...}; > Not if you really wanted private derivation. > # > #BS says "It is possible to declare some, not all, of the public > #members of a base class public memberes of a derived class." > #(page 196) Where have I gone wrong then? Could someone help me? > # > > Redeclaring the members a and f can only make the visibility MORE strict, > not less. From the AT&T C++ reference manual (pp. 70-71): "If a class > is declared to be a base class for another class using the private access > specifier, the public and protected members of the base class are private > members of the derived class." By not specifying the access in the declaration > of the derived class, base is by default private. You seem to be confusing the default classification of base's member data with what you are allowed to do when adjusting access. The code in the original posting is correct. What you cannod to is: class base { public: int a; }; class derived : public base { private: base::a; }; Here you are trying to take away access granted by default and will get the error message (from cfront 2.00): error: public member base::a specified private Ed Schiebel AT&T Bell Laboratories dog@vilya.att.com