www.digitalmars.com         C & C++   DMDScript  

D - error with D-style get'ers and set'ers ?

reply Röttgar Jones <Röttgar_member pathlink.com> writes:
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()
}
Aug 03 2003
parent "Matthew Wilson" <matthew stlsoft.org> writes:
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()
 }
Aug 03 2003