Path: utzoo!attcan!uunet!husc6!psuvax1!rutgers!columbia!garfield!fox From: fox@garfield (David Fox) Newsgroups: comp.lang.c++ Subject: Re: Friend specifier considered harmful Message-ID: <5870@columbia.edu> Date: 7 Sep 88 04:10:42 GMT References: <61@cybaswan.UUCP> <1988Sep2.174327.6439@ateng.uucp> Sender: news@columbia.edu Reply-To: fox@garfield.UUCP (David Fox) Organization: Columbia University CS Department Lines: 15 In article <1988Sep2.174327.6439@ateng.uucp> chip@ateng.UUCP (Chip Salzenberg) writes: >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. Yes, this is an example of `friend' creating *more* type security rather than less. The HashNode class need have *no* public members whatsoever, so that the class itself effectively becomes a private `member' of the HashTable class. -David Fox