Why can't I copy a const struct?

Atila Neves atila.neves at gmail.com
Sat Nov 16 02:04:02 PST 2013


> What fails is that initialization of the mutable reference on 
> the left-hand side from the const reference on the right-hand 
> side.
>
> Ali

Ah, right. In D a copy is a move followed by a post-blit and the 
move fails because the source is const, got it.

It's still silly, though. In theory the compiler could check the 
postblit constructor to see if it copies (I'm aware this might be 
easier said than done).
In my case it'll mean that I'll have to drop const off of some 
methods because of this. And they really should be const...

I hate to say it, but this is where const_cast would take care of 
the problem for me in C++.



More information about the Digitalmars-d-learn mailing list