Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!usc!jarthur!petunia!kestrel.edu!gyro From: gyro@kestrel.edu (Scott Layson Burson) Newsgroups: comp.lang.c++ Subject: Re: possible to overload << and pass an object ptr? Message-ID: <1991Mar26.061718.9358@kestrel.edu> Date: 26 Mar 91 06:17:18 GMT References: <1991Mar24.074308.28666@kestrel.edu> <1991Mar25.192002.6392@kestrel.edu> Reply-To: Gyro@Reasoning.COM Distribution: comp Organization: Kestrel Institute, Palo Alto, CA Lines: 31 In article <1991Mar25.192002.6392@kestrel.edu> I wrote: >In article Ari.Huttunen@hut.fi (Ari Juhani Huttunen) writes: >>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. I must correct myself. Overloadable `.' would do nothing of the kind, insofar as I understand the current proposal, because a pointer type cannot have member functions and therefore cannot, in particular, overload `operator.'. I think the bottom line here is that C++ provides very well for the "value model" of objects, but not very well for the "pointer model" (see the commentary that starts on p.191 of E&S). There are good reasons for providing the value model, which I don't disagree with, but I think the pointer model got unnecessarily left out in the cold. -- Scott Layson Burson Gyro@Reasoning.COM