On Tue, 24 Feb 2015 18:19:39 +0000, ketmar wrote: > On Tue, 24 Feb 2015 12:05:50 +0000, amber wrote: > >> Hi, >> >> Is it possible in D to have inheritance using value types, i.e. >> structs? >> >> Also I don't quite understand how copy ctors work in D. Do I need to >> implement opAssign(S other) {}, or this(this) {} and what's the >> difference between these two? > > there is no "copy constructor" in D. structs are copied by `memcpy()`, > and then compiler calls "postblit" aka `this(this)`. it may seem like > constructor, but it's not. it's a "fixup", that fixes inconsistencies > that are left by `memcpy()`. i.e. when postblit is called, structure is > already copied. > > and `opAssign` is... well, overloading of "=" operator. it has to > manually create a structure copy and manually copy everything you need. > and it will never be called by compiler "behind the scenes", like > postblit.
oops. of course, you already has a struct for `opAssign` -- it need `this` after all! ;-) but no automatic copying. it's just a function call, nothing magic here.
signature.asc
Description: PGP signature