Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hplabs!hpda!hpcuhb!hpindda!thh From: thh@hpindda.HP.COM (Tom Harper) Newsgroups: comp.lang.c++ Subject: Member Name Visibility Question Message-ID: <6170007@hpindda.HP.COM> Date: 6 Mar 89 19:55:40 GMT Organization: HP Information Networks, Cupertino, CA Lines: 64 I have a question concerning the visibility of member names. I cannot get an example to work as I expect based on the information found on page 281 of Stroustrup's "The C++ Programming Language". Hopefully someone can point out the error of my ways to me. The following code works as I expect: #include class baseclass { int a; public: baseclass(); int c; }; baseclass::baseclass() { c = 13; } class derived : public baseclass { public: derived(); }; derived::derived() { ; } void ef (derived& a) { cout << "a.c: " << a.c << "\n"; } main() { derived a; ef(a); } The external function ef has visibility of baseclass member c. Running the executable produces the output "a.c: 13". No surprises for me here. Example two restricts the base class in the derived class definition: #include class baseclass { int a; public: baseclass(); int c; }; baseclass::baseclass() { c = 13; } class derived : private baseclass { public: derived(); baseclass::c; // Hopefully make c visible to derived class objects. }; derived::derived() { ; } void ef (derived& a) { cout << "a.c: " << a.c << "\n"; } main() { derived a; ef(a); } This results in a compiler error telling me that c is a private member. The message is: "ef() cannot access c: baseclass is a private base class.". I expected that c would be visible to objects of class derived, since it is declared in the public member list. What am I not correctly understanding? Tom Harper thh@hpindda.HP.COM