digitalmars.D - friend functions...
- Peter Tkacz (9/9) May 04 2004 I've been doing some reading, and don't recall having seen anything on f...
- Matthew (17/26) May 04 2004 the
- Mike Swieton (10/24) May 04 2004 The only use for friends for me in C++ is for exposing internals to unit
I've been doing some reading, and don't recall having seen anything on friend functions. I also haven't done any programming in D, but would like to except avoid it until my other work has been completed, on one may as well label it the 100 year project. I do notice that there are the usual functions sine(real), cos(real), etc.. I also assume that the functions are utilized as y = sin(x);. So my question is then, if I was to create my own type myReal, with it's complex inner workings, how do I would an external function to the class have access to it's inner workings?
May 04 2004
"Peter Tkacz" <Peter_member pathlink.com> wrote in message news:c79bpt$1tlh$1 digitaldaemon.com...I've been doing some reading, and don't recall having seen anything on friend functions. I also haven't done any programming in D, but would like to except avoid it until my other work has been completed, on one may as well label itthe100 year project. I do notice that there are the usual functions sine(real), cos(real), etc.. I also assume that the functions are utilized as y = sin(x);. So my question is then, if I was to create my own type myReal, with it'scomplexinner workings, how do I would an external function to the class have access to it's inner workings?I think such things can be done by being in the same module, but I'm not sure as I haven't tried. I think the need for friend declarations are almost never borne out. I'm firmly in the Scott Meyers camp (http://www.cuj.com/documents/s=8042/cuj0002meyers/) on this one, and only ever use friend for (C++) class sharing the same header file. Since the only classes that share header files should be those that are logically inextricably linked, such as containers and their iterator/value-type classes (see the WinSTL file / reg enumeration classes for examples; http://stlsoft.org/), this is pretty rare indeed. Anyway, blather, blather. D doesn't have a friend keyword, but you can get it using modules, but you shouldn't want it other than in rare cases. Yours didactically, Matthew
May 04 2004
On Wed, 05 May 2004 10:42:44 +1000, Matthew wrote:I think the need for friend declarations are almost never borne out. I'm firmly in the Scott Meyers camp (http://www.cuj.com/documents/s=8042/cuj0002meyers/) on this one, and only ever use friend for (C++) class sharing the same header file. Since the only classes that share header files should be those that are logically inextricably linked, such as containers and their iterator/value-type classes (see the WinSTL file / reg enumeration classes for examples; http://stlsoft.org/), this is pretty rare indeed. Anyway, blather, blather. D doesn't have a friend keyword, but you can get it using modules, but you shouldn't want it other than in rare cases.The only use for friends for me in C++ is for exposing internals to unit tests, since there's no package/module-private level in C++. But in java we just use package private and in D we'd probably do the same. In other words, I agree: D has no need for a friend keyword. I would be extremely interested to see any counterexample. Mike Swieton __ The perversity of the Universe tends towards a maximum. - O'Tool's Corollary of Finagle's Law
May 04 2004