Initializing structure that is a member of a const structure

Maxim Fomin maxim at maxim-fomin.ru
Sun Mar 3 11:41:07 PST 2013


On Sunday, 3 March 2013 at 18:36:47 UTC, Maksim Zholudev wrote:
> Trying to make my program care about const qualifier I've ended 
> up with the following problem:

D's type system is not a right thing to care about.

Note, that the purpose of inout is to transmit qualifier from 
parameter to return type. Inout in constructors and void 
functions doesn't make much sense. And your code does not 
demonstrate necessity to make any of parameters as inout.

> This code would work even without opAssign but let's imagine we 
> need it for some reason.
> Is there any way to initialize `foo` without opAssign call?

Yes, const cast.

The real answer is "no", because qualifiers do not work well with 
special functions(operator overloads, constructors, destructors, 
postblits).


More information about the Digitalmars-d-learn mailing list