Taking address of properties

Robert jfanatiker at gmx.at
Thu Feb 7 10:05:50 PST 2013


Properties provide a means of access control to fields. (Range checks,
only readable, only writable, triggering a signal on change, ...)

So as posted a few times, taking the address of the ref return value of
a property is of no value at all. If you want someone to be able to take
the address of a field, you should make it simply public (without
@property), because the @property accessor methods won't gain you
anything in this case.

Having said this, I think the solution to the & operator is pretty
straight forward, it takes the address of the accessor function, which
in fact might me useful at times, but it never takes the address of the
return value. (This only applies to properties, for functions simply do
something like &(func()) to get the address of the return value.)

Tada. Problem solved :-)

I can remember Adam D. Ruppe saying that he would rather have it hidden
completely that the property is accessed by methods, so that taking the
address of the function would not be possible. I have to say, that this
does not feel right for a system programming language and it does not
really improve things, especially with @property fields.

Instead of hiding that properties are functions, we hide that there
might be a real field behind those properties.

Best regards,

Robert



More information about the Digitalmars-d mailing list