class invariants and property declarations

Steven Schveighoffer schveiguy at yahoo.com
Wed Feb 16 11:14:48 PST 2011


On Wed, 16 Feb 2011 12:47:32 -0500, Jesse Phillips  
<jessekphillips+D at gmail.com> wrote:

> Dmitry Olshansky Wrote:
>
>> Now to properties, this is actually shouldn't be allowed:
>>
>>   @property int hours;
>>
>> @property is a annotation applied to functions (getter/setter), to  
>> allow calling it with omitted () and a natural assign syntax like this:
>
> Why shouldn't it be allowed? While it provides no benefit it does  
> document that it is a property.
>

Regardless of this, you should be aware that an invariant is not called  
when a public field is changed/accessed, whether it's marked with  
@property or not.  Only member functions invoke the invariant.

-Steve


More information about the Digitalmars-d-learn mailing list