🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1847

Re: Semantics operator->()

#1847
From: Joel Bender
Date: Fri, 25 Aug 1995 02:19
43 lines
1715 bytes
In article <41gq8b$1jm@tango.cs.wustl.edu> Douglas C. Schmidt  wrote:

>         I've got a question about the behavior of operator->(), in
> particular, can it return a pointer to a builtin type?

I can never seem to find where this is defined in the ARM, but
operator->() can only return something where operator->() is defined. 
Seems kinda strange, but it makes sense.

   struct S { int s; };

   S  *p;

   class C { S *operator->(void); };

   C  c;

In this case "c->s" is OK because "c.operator->()" returns something of type 
pointer to S and you would expect to have "p->s" work.  The way I think
about this now is "p->s" is the same as "p.operator->().s".

So "c->s" is the same as "c.operator->().operator->().s".

   int *px;

So *px is meaningful, but px-> is not defined, nor is "px.operator->()".


Note that "px.operator*()" IS defined, so you could do something like this:

   class Q { int& operator*(void); };

   Q q;

Now "*q" is an integer, the same one as refered to by "q.operator*()".

Does this help?

Joel
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <jjb5-2408951819310001@bgmac1.cit.cornell.edu>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
References: <41gq8b$1jm@tango.cs.wustl.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 25 Aug 95 02:19:06 GMT
Approved: fjh@cs.mu.oz.au
Return-Path: <daemon@ncar.UCAR.EDU>
From: jjb5@cornell.edu (Joel Bender)
Newsgroups: comp.std.c++
Subject: Re: Semantics operator->()
X-Original-Date: Thu, 24 Aug 1995 18:19:31 -0400
Organization: Cornell University
Message-ID: <jjb5-2408951819310001@bgmac1.cit.cornell.edu>
References: <41gq8b$1jm@tango.cs.wustl.edu>