Why does nobody seem to think that `null` is a serious problem in D?
Neia Neutuladh
neia at ikeran.org
Wed Nov 21 03:05:07 UTC 2018
On Tue, 20 Nov 2018 23:14:27 +0000, Johan Engelen wrote:
> When you don't call `a.foo()` a dereference, you basically say that
> `this` is allowed to be `null` inside a class member function. (and then
> it'd have to be normal to do `if (this) ...` inside class member
> functions...)
That's what we have today:
module scratch;
import std.stdio;
class A
{
int i;
final void f()
{
writeln(this is null);
writeln(i);
}
}
void main()
{
A a;
a.f();
}
This prints `true` and then gets a segfault.
Virtual function calls have to do a dereference to figure out which
potentially overrided function to call.
More information about the Digitalmars-d-learn
mailing list