Thread View: comp.lang.c++
1 messages
1 total messages
Started by thh@hpindda.HP.C
Mon, 06 Mar 1989 19:55
Member Name Visibility Question
Author: thh@hpindda.HP.C
Date: Mon, 06 Mar 1989 19:55
Date: Mon, 06 Mar 1989 19:55
65 lines
1732 bytes
1732 bytes
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 <stream.h> 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 <stream.h> 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads