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

Reply via email to