Explicit default constructor for structs
Benjamin Thaut
code at benjamin-thaut.de
Wed Apr 9 11:53:58 PDT 2014
Am 09.04.2014 20:33, schrieb Timon Gehr:
> On 04/09/2014 04:59 PM, Benjamin Thaut wrote:
> Why not just:
>
> struct Foo{
> this(){
> // do stuff here
> }
> }
>
> void main(){
> Foo foo1; // error, no init value
> auto foo2=Foo(); // ok
> }
Because then the user might think, that the default constructor gets
called implicitly by the compiler. Just like in C++. But as that is not
the case the syntax should be different to indicate that a struct might
still be instaniated just using T.init.
Kind Regards
Benjamin Thaut
More information about the Digitalmars-d
mailing list