The Mask
The Mask

Reputation: 17427

Does D pass value by copy?

if I do:

myclass a = new myclass();
myclass b = a;

Does b points to or is a copy of a?

Upvotes: 2

Views: 89

Answers (1)

eco
eco

Reputation: 2229

Classes in D use reference semantics so b points to the same object as a. structs, on the other hand, use value semantics so...

auto a = mystruct();
auto b = a;

...would refer to distinct objects.

Upvotes: 8

Related Questions