Named constructors

Atila Neves atila.neves at gmail.com
Wed Jan 9 17:30:32 UTC 2019


On Wednesday, 9 January 2019 at 07:47:02 UTC, Dru wrote:
> Another way to distinguish between constructors is needed.
> Because it is possible to have two different constructors that 
> take the same arguments.
> Adding dummy arguments that are unused hurts code clarity.

Adding dummy arguments is unecessary. Just use the type system:

struct Person {
     this(FirstName firstName, LastName lastName) { /* ... */ }
}

struct FirstName { string value; }
struct LastName  { string value; }


C++ even has two libraries to do this, but D doesn't need that 
given that structs in D are much more useful (no need to write a 
constructor).


More information about the Digitalmars-d mailing list