4

D でオブジェクトを割り当てると、コピーされますか?

void main() {
    auto test = new Test(new Object());
    tset.obj;
}

class Test {
    public Object obj;

    public this(Object ref origObj) {
        obj = origObj; // Will this copy origObj into obj, or will origObj and obj point to the same data? (Is this a valid way to pass ownership without copying the object?)
    }
}
4

2 に答える 2

5

参照のみがコピーされ、オブジェクト自体は複製されません。を使用して、オブジェクトを明示的に複製でき.dupます。

于 2013-11-16T13:06:27.287 に答える