struct S { string[] s; } auto foo(string[] s...) //不能用`中`标记`s` { return S(s); //改为 return S(s.dup); } void main() { import std.stdio: writeln; writeln(foo("你好D")); }
可变参数保存在函数结束时过期的临时数组中,因而复制到GC.
可变参数
函数结束
临时数组
GC