Construct immutable member in derived class

Timoses timosesu at gmail.com
Thu Apr 5 17:42:07 UTC 2018


On Wednesday, 4 April 2018 at 22:47:07 UTC, Jonathan M Davis 
wrote:
> Because doing that basically makes it impossible to guarantee 
> that the type system isn't violated. Once an immutable variable 
> has been initialized, its value must _never_ change. It must be 
> initalized exactly once, and the compiler doesn't necessarily 
> have any clue what the base class constructors did or didn't 
> do. There's no guarantee that it even has access to the 
> function bodies for the base class when compiling the derived 
> class. So, there is no way for it to safely put off the 
> initialization of any base class members for the derived class 
> to do.
>
> - Jonathan M Davis

Ah, makes sense. I was looking for a somewhat technical answer. 
Thanks for that : ).


More information about the Digitalmars-d-learn mailing list