Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!inuxc!iuvax!rutgers!bellcore!faline!ulysses!gatech!stratus!strick
From: strick@stratus.UUCP
Newsgroups: comp.lang.c++
Subject: howcome ((*x).y) != (x->y)
Message-ID: <936@stratus.UUCP>
Date: Mon, 7-Dec-87 00:46:38 EST
Article-I.D.: stratus.936
Posted: Mon Dec  7 00:46:38 1987
Date-Received: Sat, 12-Dec-87 11:06:39 EST
Sender: news@stratus.UUCP
Reply-To: strick@gatech.edu (henry strickland)
Organization: the clouds project -- computer science -- georgia tech
Lines: 54

In an attempt to build a C++ class that mimics a pointer but that
does some invisible magic (sanity checks, offsets from a segment base, etc.)
I tried defining an arbitrary class

	struct Thing {
		int runs, hits, errors;
	};

and then a class to act as a pointer to a Thing

	class ThingRef { 

which includes a member

		Thing&    operator *();
	};


and, as expected, I was able to use "*" to dereference
ThingRefs into Things, but I was suprised that I cannot use "->" to 
dereference them.

That is, this works:

	ThingRef r;

	....    (*r).runs   .... 

but this does not work:

	ThingRef r;

	....     r->runs   ....

Is there some way that escapes me of making this work?  I also
experimented with a conversion operator "ThingRef::operator Thing()"
but was unable to find a way to make "->" work without explicit
casting.

The Book gives examples of how to define classes to mimic
integers (6.3.2), arrays (6.7), and functions (6.8), but
I cannot find an example of mimicking a pointer.

I think I have the jist the rational behind most of C++, but I cannot
see what would break or be inconstant if (x->y) were defined to be
((*x).y).    It would seem to round off one of the few rough edges.

Any help, explanations, comments?   Thanks,  strick

--
 --  henry strickland                          or
  --  the clouds project                            ihnp4!gatech!strick
   --   computer science / georgia tech
    --    atlanta ga 30332