properties - Why not the set/get syntax?
Carlos Santander
csantander619 at gmail.com
Sat Apr 1 06:56:02 PST 2006
John C escribió:
> "Cris" <central_p at hotmail.com> wrote in message
> news:e0m0an$2sd1$1 at digitaldaemon.com...
>> John C wrote:
>>> "Cris" <central_p at hotmail.com> wrote in message
>>> news:e0lr0p$2n17$1 at digitaldaemon.com...
>>>> How would you implement a write only property?
>>> Implement only the setter.
>> I mean a property that you can write but you cannot read. You can do that
>> in C#. Is it possible in D too?
>
> As I said, implement only the setter.
>
> struct Foo {
> int data_;
> void data(int value) { data_ = value; }
> }
>
> void main() {
> Foo foo;
> foo.data = 10;
> int a = foo.data; // function main.Foo.data (int) does not match
> argument types.
> }
>
>
Maybe that error message is another reason to have a true property syntax. For
someone new to D expecting data to be a property, that message is as puzzling as
it gets.
--
Carlos Santander Bernal
More information about the Digitalmars-d
mailing list