August 03, 2003 error with D-style get'ers and set'ers ? | ||||
---|---|---|---|---|
| ||||
hi everybody, i think i came across an error in the classes reference where it's about the convenient way to avoid different get and set member functions for changing a class' field. using the given example did not compile but gave me an "cannot implicitly convert int to void(int newproperty)" error message. though i am by far not 100% familiar with c-like languages i do think that the syntax is allright. so is it a bug or am i just missing a semicolon? cheers, röttgar jones ps: -- the erroneous code -- class Abc { int myprop; void property(int newproperty) { myprop = newproperty; } // set'er int property() { return myprop; } // get'er } void main() { Abc a; a.property = 3; // equivalent to a.property(3) int x = a.property; // equivalent to int x = a.property() } |
August 03, 2003 Re: error with D-style get'ers and set'ers ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Röttgar Jones | AFAIK, properties are still on the to-do list, sadly. "Röttgar Jones" <Röttgar_member@pathlink.com> wrote in message news:bgk2ak$898$1@digitaldaemon.com... > hi everybody, > > i think i came across an error in the classes reference where it's about the > convenient way to avoid different get and set member functions for changing a > class' field. > using the given example did not compile but gave me an "cannot implicitly > convert int to void(int newproperty)" error message. though i am by far not 100% > familiar with c-like languages i do think that the syntax is allright. so is it a bug or am i just missing a semicolon? > > cheers, röttgar jones > > ps: > > -- the erroneous code -- > > class Abc > { > int myprop; > void property(int newproperty) { myprop = newproperty; } // set'er > int property() { return myprop; } // get'er > } > > > void main() > { > Abc a; > a.property = 3; // equivalent to a.property(3) > int x = a.property; // equivalent to int x = a.property() > } > > |
Copyright © 1999-2021 by the D Language Foundation