strick@stratus.UUCP (12/07/87)
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 <strick@gatech.edu> or -- the clouds project ihnp4!gatech!strick -- computer science / georgia tech -- atlanta ga 30332