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.
signature.asc
Description: PGP signature
