d的类型可变参数

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.

posted @ 2022-05-25 08:16  zjh6  阅读(17)  评论(0)    收藏  举报  来源