fields in @property ?
MIURA Masahiro
echochamber at gmail.com
Tue Jan 12 23:30:39 PST 2010
Hi,
Is it ok to have fields in @property ?
Implementing properties often require private fields to hold the
values, and it seems natural to have them inside @property near
the property methods. But I couldn't find any mention in the docs
about fields in @property.
This compiles with DMD 2.039, and runs fine:
---- cut here ----
import std.stdio;
class Foo
{
this(string msg) { this._msg = msg; }
@property {
private string _msg; // <-- field in @property
string msg() { return _msg; }
}
}
void main()
{
auto foo = new Foo("Hello world");
writeln(foo.msg);
}
---- cut here ----
More information about the Digitalmars-d-learn
mailing list