Re: Asserting that a base constructor is always called

2020-05-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 24, 2020 12:38:46 AM MDT Tim via Digitalmars-d-learn 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? 1. If you wanted to run any code before calling the

Re: Asserting that a base constructor is always called

2020-05-24 Thread Nicholas Wilson via Digitalmars-d-learn
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

Re: Asserting that a base constructor is always called

2020-05-24 Thread Tim via Digitalmars-d-learn
On Sunday, 24 May 2020 at 00:51:17 UTC, Jonathan M Davis wrote: 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

Re: Asserting that a base constructor is always called

2020-05-23 Thread Jonathan M Davis via Digitalmars-d-learn
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

Re: Asserting that a base constructor is always called

2020-05-23 Thread Tim via Digitalmars-d-learn
On Saturday, 23 May 2020 at 22:15:49 UTC, Ali Çehreli wrote: Is it not already called? I tried the following and it seems to work: import std.stdio; GameObject[1] world; enum layer = 0; /// Base class of most objects in the game class GameObject{ this(){ world[layer] = this;

Re: Asserting that a base constructor is always called

2020-05-23 Thread Ali Çehreli via Digitalmars-d-learn
On 5/23/20 3:04 PM, Tim wrote: I have a base class GameObject: /// Base class of most objects in the game class GameObject{     this(){     world[layer] = this;     }     abstract void update(){}     void draw(){} } I want to make sure that whenever a class inherits from this, the