Re: Propogating constness through a const member
Crosbie Fitch wrote:
Whoever solves this has effectively enabled zero-overhead properties to
enter the C++ language (payload incurring properties are already doable).
After reading the code that you posted on comp.std.c++, I finally
figured out that this was what you were after. Basically, you're
trying to use an anonymous union to achieve two things:
(1) emulate multiple virtual inheritance without the ususal space
overhead and
(2) bind names to different "typed views" of the same object (which
would be different base classes, if multiple inheritance were used
instead of a union) without the space overhead of reference members
As you know, reading and writing through different members of a union
yields undefined behavior. To my mind, this renders unions an entirely
unsuitable tool for implementing properties. Others' opinions may
differ.
The good news is that #1, above, is achievable by different means. #2,
the naming problem, is harder. As far as I can tell, the best that can
be achieved in the current language (without space overhead) requires
property names to be used with function call syntax. In other words:
T t, u;
t.some_property() = u.some_property();
t.other_property() = 5;
rather than the preferred
T t, u;
t.some_property = u.some_property;
t.other_property = 5;
To get to the preferred syntax with no space overhead, we'd need to add
a feature to the language: zero size member references. (These would
be member references bound -- perhaps by in-class-body initializers --
to subobjects, including base class subobjects, of the containing
object.)
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]