Article View: comp.std.c++
Article #567"->" == "." proposal
From: Jim Miller
Date: Tue, 30 Oct 1990 18:15
Date: Tue, 30 Oct 1990 18:15
41 lines
1799 bytes
1799 bytes
I'd like suggest a modification for C++:
Make "." and "->" equivalent.
"a.b", if "a" is a pointer, becomes "(*a).b".
"x->y", if "x" is a structrue/class, becomes "x.y" --
unless "->" has been overloaded for x.
Any problems?
Commentary:
A while ago, due to a design error, I had to change a pointer to a
structure to a local structure, and similarly a local structure to a
pointer to a structure. The compiler told me in each case that the
"." or "->" was wrong.
Good, but if it can tell me that a.b is an error because a is a pointer,
why can't it turn it into "a->b" or "(*a).b)"?
Similarly, it tells me that x->y is an error because x is not a pointer
but a structure, why can't it turn the "x->y" into a "x.b"?
From my point of view, what I'm doing is getting an element out of
a structure, and having to decide if the variable is the structure or
a pointer to a structure is a silly thing for me to have to know,
especially since the compiler knows explicitly, since I told it so
earlier. No ambiguity.
In the case of an overloaded "x->", "x->y" would not become "x.y" if
"x" was a structure instead of a pointer.
Responses? Problems? Opinions?
jim miller
jamiller@hpmpeb7.cup.hp.com
(a.k.a James A. Miller; Jim the JAM; stupid; @!?$$!; ... )
Anything I say will be used against me ...
But my company doesn't know or approve or condone anything of mine here.
Technical Details
Message-ID:
<52390002@hpcupt1.cup.hp.com>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!hpcc05!hpcuhb!hpda!hpcupt1!jamillerShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!hpcc05!hpcuhb!hpda!hpcupt1!jamiller From: jamiller@hpcupt1.cup.hp.com (Jim Miller) Newsgroups: comp.std.c++ Subject: "->" == "." proposal Message-ID: <52390002@hpcupt1.cup.hp.com> Date: 30 Oct 90 18:15:22 GMT Organization: Hewlett Packard, Cupertino Lines: 41