null this

rikki cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Nov 21 02:34:26 PST 2016


On 21/11/2016 11:25 PM, Satoshi wrote:
> Hello,
> how can calling method on local struct throw "null this"?
> struct is initialized by .init and have default values.
>
>
> struct Foo {
> Bar bar;
>
>     static struct Bar {
>         float x, y, z;
>     }
>
> Bar getBar() {
> return bar;
> }
>
> }
>
>
> then
> Foo foo = Foo.init;
> auto b = foo.getBar(); // throw "null this"

Well that code definitely works fine as is.
Perhaps remove that static, it makes me a little queasy just looking at it.

Also no need to set foo to Foo.init, it already is that value.


More information about the Digitalmars-d-learn mailing list