Re: Can I overload with unused arguments to make the code clear?
In article <513fa7e1$0$32111$14726298@news.sunsite.dk>,
use_my_alias_here_at_hotmail_com@tellus.orb.dotsrc.org (DeMarcus) wrote:
Is it justifiable to introduce a NullEntertainer, instantiate it as
NULL_ENTERTAINER and then overload watchShow() with a
NullEntertainer argument that isn't used, just to make the code
slightly more clear and explicit to read?
Yes. Although I wouldn't use all-capitals for a name which wasn't a
macro. I would probably use an enum rather than a class, which is
slightly lighter weight. For example, I have used:
enum Utf8_ { Utf8 };
enum Utf16_ { Utf16 };
enum Utf32_ { Utf32 };
StringUtf8 source( "sample" );
StringUtf16 destination( Utf8, source );
Here the first enum value isn't used, but the type is used to
statically resolve a conversion. It's redundant because the type of
source has the same information, but requiring it makes the conversion
more explicit. (In practice I'd give them different values in case
someone wanted to test or print them at run time.)
Or are there better ways to solve this?
Sometimes renaming the function is clearer. Using the same function
name allows some (compile-time) polymorphism, but if you don't need it
then using a different function name makes the declarations cleaner
without adversely affecting the caller.
a.watchNullShow();
-- Dave Harris, Nottingham, UK.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]