Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!jarthur!petunia!kestrel.edu!gyro From: gyro@kestrel.edu (Scott Layson) Newsgroups: comp.lang.c++ Subject: Re: possible to overload << and pass an object ptr? Message-ID: <1991Mar25.192002.6392@kestrel.edu> Date: 25 Mar 91 19:20:02 GMT References: <1991Mar24.074308.28666@kestrel.edu> Reply-To: Gyro@Reasoning.COM Organization: Kestrel Institute, Palo Alto, CA Lines: 27 In article Ari.Huttunen@hut.fi (Ari Juhani Huttunen) writes: >In article <1991Mar24.074308.28666@kestrel.edu> gyro@kestrel.edu (Scott Layson) writes: > >>For these reasons I have toyed with the idea of proposing to the >>committee a system for declaring "member functions" on the type `C*' >>where C is some class, so that your first example could be made to >>work without the two-level class structure. Unfortunately, I have >>never managed to come up with a proposal I find adequately elegant. > >How about this one? > >struct S { >friend void operator<<(S *s, char p1) { *s << p1; } > void operator<<(char p1) { cout << p1; } >}; Ah. Indeed that works for the specific example under consideration. I was thinking of the example I had encountered in the past, where I basically wanted to hide from the outside world the fact that a class was implemented as a pointer. So, I wanted to say `obj.mfunc()' rather than `obj->mfunc()'. Granted, overloadable `.' would accomplish this. I seem to recall, however, that that still isn't all I wanted. Let me think about this. -- Scott Layson Burson Gyro@Reasoning.COM