Path: utzoo!attcan!uunet!mcvax!ukc!reading!cf-cm!cybaswan!eeartym From: eeartym@cybaswan.UUCP (Dr R.Artym eleceng ) Newsgroups: comp.lang.c++ Subject: Re: Friend specifier considered harmful Message-ID: <78@cybaswan.UUCP> Date: 12 Sep 88 02:48:16 GMT References: <61@cybaswan.UUCP> <1988Sep2.174327.6439@ateng.uucp> Reply-To: eeartym@cybaswan.UUCP (Dr R.Artym eleceng ) Organization: University College of Swansea Lines: 33 In article <1988Sep2.174327.6439@ateng.uucp> chip@ateng.uucp (Chip Salzenberg) writes: > Well, there is almost no language feature which is truly indispensible, but > I used "friend" once where it proved very useful: an implementation of a > hash table. > > The HashTable class contains an array of pointers to HashNode. Each > HashNode contains a pointer to the next HashNode. I made HashTable a friend > of HashNode. This allowed easy access to the HashNode "next" pointer but > _only_ for HashTable member functions. I see no reason why the HashTable can't request the preceding HashNode to place the new HashNode pointer in its next field. This seems tidier anyway, since the first HashNode in each chain is linked to the HashTable array and thus this operation belongs in HashTable, whereas subsequent chaining alters the contents of a HashNode and therefore belongs in a HashNode member. Inline dispenses with the efficiency argument. Why this structure anyway? --- it's the C approach, not C++! You ought to have an array of lists in HashTable, with the lists carrying HashNode objects without a next field. The nice thing about C++ is that such a more-OO split is not necessarily any less efficient. -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Keywords: Parallel, Applicative, and Object-Oriented Languages and Systems --------------------------------------------------------------------------- Dr. Richard Artym, + UUCP : ..!ukc!pyr.swan.ac.uk!eeartym Electrical Engineering Dept., + JANET : eeartym@uk.ac.swan.pyr University of Wales, + Phone : [(0792) or (+44 792)] 295536 Swansea, SA2 8PP, + Fax : [(0792) or (+44 792)] 295532 U.K. + Telex : 48358 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~