Opaque structs
Johannes Pfau
nospam at example.com
Sat Jun 29 01:01:16 PDT 2013
Am Fri, 28 Jun 2013 22:16:33 +0200
schrieb Andrej Mitrovic <andrej.mitrovich at gmail.com>:
> On 6/28/13, Johannes Pfau <nospam at example.com> wrote:
> > A naive question: Why isn't struct S {} enough? This should be a
> > struct with size 0 so why do we need to disable the constructor and
> > postblit explicitly?
>
> Because the user should never be able to use such a struct by value,
> in other words a user might mistakenly write code such as:
>
> S s2 = *s; // copies 1 byte
But why is that legal / does that copy _one_ byte? It seems like that's
totally arbitrary. Shouldn't doing anything value-related on
an empty struct be invalid anyway?
More information about the Digitalmars-d-learn
mailing list