safety: null checks

Dibyendu Majumdar mobile at majumdar.org.uk
Sun Nov 22 11:52:13 UTC 2020


import core.stdc.stdio : printf;

extern (C++) abstract class A {
     void sayHello();
}

extern (C++) class B : A {
     override void sayHello() {
         printf("hello\n");
     }
}

extern (C) void main() {
     //scope b = new B;
     B b;
     assert(b);
     b.sayHello();
}


Above fails because b is null. But why doesn't the compiler say 
so? It seems like a very basic safety check.


More information about the Digitalmars-d mailing list