Struct default constructor - need some kind of solution for C++ interop

John Colvin via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 8 03:06:16 PDT 2016


On Wednesday, 7 September 2016 at 22:31:17 UTC, Walter Bright 
wrote:
> S is initialized to a valid state, meaning the fields are not 
> filled with garbage, and are in a state expected by the member 
> functions.

We can write member functions that require a state other than the 
initial state. I don't see what's special about this init state.

There are arguably also types that don't have any valid init 
state, I think mutexes fall in to this category.

> But if there's a default constructor,
>
>     S s = S.init;
>     S s;
>
> which is correct?

They are different, one has the initial state (pre-construction) 
and the other has the state post-default-construction.

I think it's too late for this stuff now for D anyway. There are 
workarounds that make life acceptable without default 
constructors, I can't see how we could add them without getting 
into a real mess.


More information about the Digitalmars-d mailing list