rebind of const class variables
qqiang via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jan 20 01:29:45 PST 2015
I am writing a tree data structure, and I have the following code:
```D
final class Node {
private {
int val_;
Node parent_;
Node left_;
Node right_;
}
@property
const(Node) maximum() const {
auto ret = this;
while (ret.right_) {
ret = ret.right_;
}
return ret;
}
}
```
It failed to compile and complaint that `cannot modify const
expression ret`。
Since `ret` is just a binding to a const class object, why can't
I rebind it to another const class variable?
Must I use pointers to cope with this?
Thx
More information about the Digitalmars-d-learn
mailing list