null this, classes, methods and "null this" assertion
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Fri Apr 10 19:06:53 PDT 2015
On 4/10/15 9:59 PM, ketmar wrote:
> let's take a code like this:
>
> import std.stdio;
>
> class A {
> size_t len = 42;
> final size_t length () const { return (this !is null ? len : 0); }
> }
>
> void main () {
> A a;
> writeln(a.length);
> a = new A();
> writeln(a.length);
> }
>
> in "-release" mode this code outputs "0" and "42", as expected (by me).
> but without "-release" is raises "null this" assertion.
In non-release mode, it's calling the invariant, which is a virtual
function.
-Steve
More information about the Digitalmars-d
mailing list