Asserting that a base constructor is always called

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sun May 24 00:51:17 UTC 2020


On Saturday, May 23, 2020 4:43:04 PM MDT Tim via Digitalmars-d-learn wrote:
> It is but I want to make sure for other cases in the future where
> I create a new class that inherits from GameObject. This was I
> can avoid future bugs by ensure that all classes in the future
> that inherit from GameObject, call it's constructor

The base class constructor will _always_ be called. There's no need to worry
about it. Even if you hadn't declared one, the compiler will provide a
default constructor, because classes have to have a constructor. And if you
had declared a constructor in your base class but no default constructor,
then you'd get a compile-time error if your derived class' constructor
didn't explicitly call it.

- Jonathan M Davis





More information about the Digitalmars-d-learn mailing list