On 07/09/2018 11:18 AM, Flaze07 wrote:
class Game
{
[...]
RenderWindow win;
[...]
void init()
{
[...]
auto win = new RenderWindow( VideoMode( 600, 600 ), "snake" );
[...]
}
void run()
{
[...]
writeln( win is null );
[...]
}
}
the problem here is, during init(), the writeln will output false, which
means yes win is initialized, however during run(), suddenly win is null
becomes true...
The `win` you're creating in `init` is a function-local variable. It
ceases to exist when `init` returns. It's not `this.win`.
In `run`, you're accessing `this.win`. It's still null because you never
assigned anything there.
So change `auto win = ...;` to `this.win = ...;` or simply `win = ...;`.