例項化
class Lion
{
private double weight; // only accessible with-in class
this(double weight)
{
this.weight = weight;
}
double weightInPounds() const @property // const guarantees no modifications
// @property functions are treated as fields
{
return weight * 2.204;
}
}
void main()
{
import std.stdio : writeln;
auto l = new Lion(100);
assert(l.weightInPounds == 220.4);
writeln(l.weightInPounds); // 220.4
}