Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: possible to overload << and pass an object ptr? Message-ID: <636@taumet.com> Date: 27 Mar 91 18:03:48 GMT Article-I.D.: taumet.636 References: <1991Mar24.074308.28666@kestrel.edu> <1991Mar25.192002.6392@kestrel.edu> Organization: Taumetric Corporation, San Diego Lines: 20 Ari.Huttunen@hut.fi (Ari Juhani Huttunen) writes: |Ari>struct S { |Ari>friend void operator<<(S *s, char p1) { *s << p1; } |Ari> void operator<<(char p1) { cout << p1; } |Ari>}; |No, this does not work. Or at least it does not work with g++ 1.37.1. The |error is: | operator has no user-defined argument type |(meaning the friend operator.) Though I think this _should_ work. It should _not_ work. It has always been a requirement that an overloaded operator function must have at least one parameter of class type. A pointer to a class type is not a class type. We can argue about whether the restriction should be relaxed (I don't believe it should be), but the language definition make the code illegal. -- Steve Clamage, TauMetric Corp, steve@taumet.com