readonly?

Tobias Pankrath tobias at pankrath.net
Tue Jul 10 13:56:21 PDT 2012


On Tuesday, 10 July 2012 at 19:27:56 UTC, Namespace wrote:
> Maybe D need's a readonly keyword.
> Sometimes i have a class which can take an object from 
> everywhere to store it. So it can not be const, because i 
> didn't just initialized it with a ctor.
> But i don't want to change the object, i only want to read or 
> call const methods. What now?
> I'd suggest a readonly keyword for that.
>
> [code]
> class Foo {
> readonly:
>     Bar _b;
>
> public:
> void SetBar(readonly Bar b) {
>     _b = b;
> }
> }
> [/code]
>
> Or has D an alternative?

const(T)* ?




More information about the Digitalmars-d-learn mailing list