Re: function call without ()
Richard Smith wrote:
Perhaps the solution is not to introduce some new C#-like property
syntax, but instead to have a way of saying that a member should take
up no space. The bit-field syntax already provides a way of doing this
(though only integral or enum types are currently allowed, and zero has
a special meaning). It would only take a very minor language change to
make the following legal
struct C {
struct {
operator int() const { return 42; }
} m : 0;
};
I think there's an issue that affects any solution that relies on
"property objects" -- basically, the inability to overload the "."
operator means that we can't construct a type that behaves like a
reference...so we can't create a property type T1 that behaves like a
T2&. We can, however, create a function which (when called) behaves
like a T2& (because it returns a T2&). That's one of the reasons for
wanting to implement "properties" as function calls rather than as
objects (even zero sized ones).
Now, I did think about the idea of zero-sized reference members, but
that led to other snarls. For instance, getting "const correct"
behavior from reference members requires special rules, while ordinary
member function overloading gives us the "right" behavior for free.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]