scope(exit) and destructor prioity

Sasszem mch at atw.hu
Mon Sep 18 20:55:21 UTC 2017


On Monday, 18 September 2017 at 20:30:20 UTC, Jerry wrote:
> On Monday, 18 September 2017 at 20:26:05 UTC, Sasszem wrote:
>>  [...]
>
> It's called inbetween the destructors of wherever you put the 
> scope(exit).
>
> import std.stdio;
>
> struct De
> {
> 	~this() { writeln("De"); }
> }
>
> void main()
> {
> 	De a;
> 	scope(exit) writeln("scope exit");
> 	De b;
> }
>
>
> Output:
> De
> scope exit
> De

If I write "auto a = new De()", then it calls the scope first, no 
matter where I place it.


More information about the Digitalmars-d-learn mailing list