struct and default constructor

monarch_dodra via Digitalmars-d digitalmars-d at puremagic.com
Fri Oct 10 14:19:01 PDT 2014


On Sunday, 27 November 2011 at 19:50:24 UTC, deadalnix wrote:
> Hi,
>
> I wonder why struct can't have a default constructor. TDPL 
> state that it is required to allow every types to have a 
> constant .init .
>
> That is true, however not suffiscient. A struct can has a 
> void[constant] as a member and this doesn't have a .init . So 
> this limitation does not ensure that the benefit claimed is 
> garanteed.
>
> Additionnaly, if it is the only benefit, this is pretty thin 
> compared to the drawback of not having a default constructor.

Think the argument is that declaring `T t;` must be CTFE, which 
kind of implies a T.init state (which may have non-deterministic 
values in the presence of " = void").

This is mostly for declaring things static, and the whole 
"constructors are run after the .init blit".

But even then:
T t; //value is T.init, if not @disable this()
T t = T(); //Potentially run-time

I've started threads and tried to start discussions about this 
before, but to no avail. It's a relativelly recurrent complain, 
especially from "newer" C++ users. The older D users have either 
of thrown in the towel, or implemented "workarounds".


More information about the Digitalmars-d mailing list