cannot cast

Namespace rswhite4 at googlemail.com
Thu May 3 01:54:47 PDT 2012


On Thursday, 3 May 2012 at 08:46:26 UTC, Chris Cain wrote:
> On Thursday, 3 May 2012 at 08:00:43 UTC, Namespace wrote:
>> So, you mean that if i declared any parameter as const, it 
>> have to stay const all the time?
>
> Yes. const = you can't change. Changing it is invalid behavior. 
> Imagine const/immutable as bits in readonly memory and you'll 
> have to right mindset.
>
>> What would you do, if you need in a special case a mutable 
>> version or must change the object itself?
>> Because there is no "mutable" keyword in D you have to cast 
>> away the constness.
>
> In what way do you mean? If it's something you honestly _need_ 
> to change and it's const, then maybe throwing an exception 
> would be appropriate.

I thought that const = "cannot change directly" and immutable 
stands for "cannot change all the time". If not, why exist both 
storage classes beside?


More information about the Digitalmars-d-learn mailing list