import std.stdio; @safe: unittest { void delegate()[] dgList; foreach(int i; [1, 2, 3]) { int b = 2; dgList ~= { writeln(b); }; writeln(&b); //报错,d不能取出域变量地址. } }
超过引用变量的闭包字面的正确行为是,分配闭包.这里也是.
引用
闭包字面
分配闭包