Asserting that a base constructor is always called
Tim
t.oliver at windowslive.com
Sat May 23 22:43:04 UTC 2020
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;
> writeln("called");
> }
>
> abstract void update(){}
>
> void draw(){}
> }
>
> class A : GameObject {
> this(int i) {
> writeln(__FUNCTION__);
> }
>
> override void update() {
> }
> }
>
> void main() {
> auto a = new A(42);
> }
>
> Ali
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
More information about the Digitalmars-d-learn
mailing list