discrimination of constructors with same number of parameters
Lutger Blijdestijn
lutger.blijdestijn at gmail.com
Thu Dec 30 05:46:06 PST 2010
sybrandy wrote:
> Why not have something like this:
>
> this (int[] data, string text, bool isMessage = false) {...}
>
> Then, if you just pass in two parameters you treat it as a filename and
> if you pass in a "true" for the third parameter, it's a message. It's
> not quite what you're looking for, but it's simple and pretty clean.
>
> Casey
If you opt for this solution, an enum is slightly more verbose but much
clearer:
enum IsMessage
{
Yes,
No
}
this (int[] data, string text, IsMessage isMessage = IsMessage.No) {...}
auto s = new S(data, text, IsMessage.Yes);
vs
auto s = new S(data, text, true);
I would still prefer a factory method or a struct wrapper though.
More information about the Digitalmars-d-learn
mailing list