[Effective-cpp] Item 18: Make interfaces easy tousecorrectlyandhard to use incorrectly
Balog Pal
pasa at lib.hu
Thu Jul 6 06:37:08 EDT 2006
>> enum Month { Jan=1...Dec=12 };
>
>> values apart from 1-12 are valid, so must jump though hoops to prevent
>> such things!
>
> Yes, Date(2006, Jan, 2) is unlikely to be ambiguous.
> Even Date(Jan, 2, 2006) isn't going to be a problem either.:-)
> But Date(2006, 1, 2) isn't going to compile.
Yeah, I think it's a good compromissum that will catch most of the problems
with the least disturbance of the force.
It's a shame C++ doesn't have some ADL-like thing specific to enums
though -- most time around you will have ugly qualifiers on enum members, or
put them outside the class they would belong and possibly add some prefix.
:( If the above used in live code I'd use the full names for each month.
And add a helper function that converts int->Month to encapsulate the cast.
More information about the Effective-cpp
mailing list