Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!mit-eddie!mizar.docs.uu.se!perm From: perm@mizar.docs.uu.se (Per Mildner) Newsgroups: comp.lang.c++ Subject: overloading operator-> Message-ID: <8906011506.AA06488@mizar.DoCS.UU.SE> Date: 1 Jun 89 15:17:10 GMT Sender: daemon@eddie.MIT.EDU Lines: 39 Jonathan Shopiro and Jerry Schwarz of AT&T both supplied the correct code to do what I wan't. operator-> should be declared to return a pointer. I still don't understand why g++ refuses to inline code it. class Object { public: int a; }; class Pointer { int data; public: Object* p; Object* operator ->(); Object& operator *(); }; inline Object* Pointer::operator ->() { // won't inline return p; }; inline Object& Pointer::operator *() { // inline ok return *p; }; int main (int argc, char* argv[]) { Object O; Pointer P; P.p = &O; (*P).a = 20; // why does this inline P->a = 10; // and not this? return P->a; }; /* [g++-1.35.1-] mizar 3% g++ -Wall -O -g operator-test.cc operator-test.cc:18: warning: inline declaration ignored for function with `...' */