Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!usc!samsung!emory!gatech!udel!rochester!kodak!islsun!cok From: cok@islsun.Kodak.COM (David Cok) Newsgroups: comp.lang.c++ Subject: difference between friend and static member function Message-ID: <1991Feb27.153602.19495@kodak.kodak.com> Date: 27 Feb 91 15:36:02 GMT Sender: cok@Kodak.COM Organization: Eastman Kodak Co., Rochester, NY Lines: 36 One use of friend declarations is to allow members of other classes (or entire other classes) access to the internals of a given class. Aside from that use, what can one do with friend functions that one cannot do with *static* member functions? 1) static member functions will have conversions applied to all arguments, just like friends. 2) static member functions can be declared private; friends cannot. This makes static members better for functions which are not really part of the interface but are needed for the implementation (and non-static members are not wanted). 3) static members must be accessed using the class::fcn notation (or using a dummy object); friends can be called directly. BUT 4) The compiler (Sun C++ 2.0 on a SparcStation) complains about static myclass operator+(myclass,myclass) saying error: myclass::operator +() must take 0 or 1 arguments This seems to me to be a bug since there is no implied this argument for a static member. Right or wrong? Except for the problem in 4 (which only applies to operators) and the difference in syntax in 3, it seems friends could generally be replaced by static members. Any comments? David R. Cok Eastman Kodak Company cok@Kodak.COM