@disable this for structs

Adam D. Ruppe destructionator at gmail.com
Thu Feb 27 10:13:53 PST 2014


Basically, disabling the default constructor just forces the user 
to think about what they want there to initialize it, which also 
gives you a chance to check their values or funnel them toward a 
particular constructor/factory method.

They can still choose to explicitly leave it unitialized with 
=void, or call a constructor with some value.

Just when you write

Foo f;

and the compiler complains that default constructor is disabled, 
now you have to actually think about what to do next. If you 
consult the docs, it might say "use Foo.create() instead" and now 
you know. Or you might give it some value that makes sense.


More information about the Digitalmars-d-learn mailing list