Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!rex!ginosko!fialli From: fialli@ginosko.samsung.com (Joe Fialli) Newsgroups: comp.lang.c++ Subject: Why can't access control be used to disambiguate between base class members? Keywords: base class member, ambiguity, access control, type checking Message-ID: <2408@ginosko.samsung.com> Date: 31 Jul 89 15:57:29 GMT Organization: Samsung Software America, Inc. Lines: 60 I was wondering if anyone could offer an explaination for the following rule taken from the AT&T C++ Release 2.0 Product Reference Manual,Section 10.1.1, page 65. (In the context of multiple base classes,) Access to base class members must be unambiguous. ... The check for ambiguity take place before access control and before type checking. The following shorten example taken from the reference manual illustrates the intent of this rule. class A{ public: int a; }; class B{ private:int a; }; class C : public A, public B {}; void g(C* pc) { pc->a = 1; //error, ambiguous: A::a or B::a ? } I feel that access control rules could have been used to disambiguate the reference to data member a. Data member a is declared private in class B; therefore, a is not accessible in function g. Why should the user have to explicitly disambiguate this reference when a reference to pc->(B::a) would result in an error message stating that member a is not visible ? Additionally, I feel this rule pollutes the name space for accessing members acquired via multiple base classes. For example: class UsefulClassFromALibrary{ private: void common_name( void ); public: void public_name( void ); }; class UserClass { public: void common_name( void ); }; classMultDerived : public UsefulClassFromALibrary, public UserClass {}; void foo( void ) { MultDerived C; C.common_name(); // error, ambiguity between // private UsefulClassFromALibrary::common_name(); // and // public UserClass::common_name(); } This example shows how there can easily be name clashes between private members of classes taken from some library of useful classes and a user created classes. I would think one advantage to declaring members private to a class is to keep the name space to be inherited by classes derived from this library class as small as possible. In summary, I was just wondering why access control and type checking can not be used to disambiguate access to base class members?