Asserting that a base constructor is always called
Nicholas Wilson
iamthewilsonator at hotmail.com
Sun May 24 07:24:20 UTC 2020
On Sunday, 24 May 2020 at 06:38:46 UTC, Tim wrote:
> Oh right. I mean it makes sense but I got confused when super()
> is valid syntax. Why would you need to call the super
> constructor when it's called automatically?
A base class with a constructor that has no args will
automatically get called at the start of a child class if it is
not explicitly called. You can call it yourself anywhere in an
always executed branch of the constructor. As for why, if you
wanted to do some logging before the base constructor was called.
You need to call the base class's constructor explicitly when it
has arguments and there is no default constructor in the base
class. This must be done in an always executed branch. This must
be called or the compiler will issue an error.
More information about the Digitalmars-d-learn
mailing list