discrimination of constructors with same number of parameters

"Jérôme M. Berger" jeberger at free.fr
Thu Dec 30 08:10:00 PST 2010


Steven Schveighoffer wrote:
> What I would suggest is static factory methods.  The issue with any kind
> of typedef (be it with the soon-to-be-deprecated typedef keyword or with
> a proxy struct), is that what does this mean?
> 
> auto obj = new Foo([1, 2, 3], "blah");
> 
> Is "blah" a filename or a message?
> 
--> Error, Foo (int[], string) does not exist.

> Whereas, if you use factory methods:
> 
> auto obj = Foo.createWithFilename([1,2,3], "blah"); // "blah" is a filename
> auto obj = Foo.createWithMessage([1,2,3], "blah"); // "blah" is a message
> 
> The code becomes crystal clear.  Reduce verbosity as you see fit ;)
> 
auto obj = new Foo ([1, 2, 3], Filename ("blah"));
auto obj = new Foo ([1, 2, 3], Message ("blah"));

		Jerome
-- 
mailto:jeberger at free.fr
http://jeberger.free.fr
Jabber: jeberger at jabber.fr

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20101230/65b40966/attachment.pgp>


More information about the Digitalmars-d-learn mailing list