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: <79@cybaswan.UUCP> Date: 12 Sep 88 02:50:23 GMT References: <61@cybaswan.UUCP> <1988Sep2.174327.6439@ateng.uucp> <8163@alice.UUCP> Reply-To: eeartym@cybaswan.UUCP (Dr R.Artym eleceng ) Organization: University College of Swansea Lines: 35 In article <8163@alice.UUCP> bs@alice.UUCP (Bjarne Stroustrup) writes: > A friend function can be used to express that coercion is acceptable > for the left hand operand of an operator. Such coercions are not aceptable > for the left hand operand of an operator defined as a member function: > ... program ... > This could be expressed without the use of friend functions (but not > in C++, since you cannot specify a member function for a built-in type > so int::operator(Int) cannot be defined). It could, however, also be > expressed without the use of member functions. > It can also be expressed without the use of coercions, but that leads > to an explosion of operator functions. I reckon this is the only convincing reason for using the friend specifier mentioned so far in this discussion. It is important to note that it stems from a limitation in C++ as it stands at the moment, and does not imply that loosening the class scope walls is a good thing. Furthermore, this kind of usage is completely benign, really just a syntactic artifice: the scope region does not flood out into another class. This pours some light on the real source of my discomfort --- my original phrase should perhaps be amended to `Friend classes considered harmful'. Such sledgehammer usage of the specifier probably indicates a non-OO design approach or that structural soundness has been sacrificed for efficiency. (Examples to the contrary still welcome!) -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~