User defined properties signatures

dvic via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Apr 20 11:35:34 PDT 2015


Hi guys,

It seems it's possible to define different read properties, only
differing by the return type.

Ex:

@property string value() { return m_value; } // m_value is a 
string
@property int value() { return to!int(m_value); }

But when using it in writefln() or assert for example, compiler 
(dmd) complains
about 2 different property signatures.

What I'd like to have is this:

MyObject.value = "12345"; // write property always setting a 
string

assert(MyObject.value == "12345");  // depending on the context, 
call 1st prop
assert(MyObject.value == 12345);  // depending on the context, 
call 2nd prop

Why is the compiler not complaining about defining 2 read 
properties and it does
otherwise when using both of them?

Any clue?

Thanks a lot.



More information about the Digitalmars-d-learn mailing list