subclass instance construction

Tomek Sowiński just at ask.me
Fri Nov 5 16:16:50 PDT 2010


spir napisał:

> I have a weird bug related to class instance construction. My guess is
> that it seems a superclass's this() is implicitely called (before the
> subclass's one, if any), even if overriden and without any use of "super".
> In my case, I have schematically:
> 
> === super class ===
> this() {
> doThis();
> }
> === sub class ===
> this() {
> doFirst();
> doThis();
> }
> 
> All happens as if doThis was performed before doFirst... and performed
> again after doFirst! At least, that's what debug output shows, and it
> would correctly explain the bug. Strange. How should I express what I
> mean?

"If no call to constructors via this or super appear in a constructor, and the 
base class has a constructor, a call to super() is inserted at the beginning of 
the constructor."

http://d-programming-language.org/class.html#Constructor

-- 
Tomek


More information about the Digitalmars-d-learn mailing list