inheriting constructos

Michel Fortin michel.fortin at michelf.com
Mon Nov 30 08:31:11 PST 2009


On 2009-11-30 10:30:11 -0500, Andrei Alexandrescu 
<SeeWebsiteForEmail at erdani.org> said:

> class MyException : Exception {
>      private int sysCode;
>      invariant() { assert(sysCode < 100); }
> }
> 
> If default initialization of the field puts it in a state that respects 
> the invariant, there isn't a problem.

I think this simply shows that if super's constructor is inherited, 
once the object is constructed invariant() should be called (and not 
super's invariant, the one of the object actually constructed). If you 
do that you'll catch any field not respecting the invariant right after 
construction.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list