July 23, 2013 Shallow constness? | ||||
---|---|---|---|---|
| ||||
Is there an attribute that can make member variables of a class read-only without having to declare them as const or immutable (const all the way down)? I saw that one can define a getter function without a setter to achieve this behavior, but that seems like a little bit of a hack. |
July 23, 2013 Re: Shallow constness? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Maxime Chevalier-Boisvert | On Tuesday, 23 July 2013 at 18:01:58 UTC, Maxime Chevalier-Boisvert wrote:
> I saw that one can define a getter function without a setter to achieve this behavior, but that seems like a little bit of a hack.
As far as I am aware, it is not a hack, but recommended practice. It actually does make sense - what you want has nothing to do with actual mutability of a member (at least within D concept of mutability) but is more like a tool for controlling access to it.
|
Copyright © 1999-2021 by the D Language Foundation