Re: Template conversion and default copy constructor
James Dennett wrote:
Matthias Hofmann wrote:
"kanze" <kanze@gabi-soft.fr> schrieb im Newsbeitrag
news:1153732876.025294.204870@75g2000cwc.googlegroups.com...
As a general rule, I would say that you shouldn't overload
functions if it will make a difference which one would be
called.
Why would you overload functions if it does not make a
difference which one will be called?
(1) To allow calling with a wider range of argument types
(2) For efficiency
On the other hand, why would you design an interface such that
a user has to consider the result of overload resolution in
order to know which operation will be performed? If they
operations are that different, they should have different
names.
That's really what I was trying to say. You just expressed it a
lot better.
Of course, when it comes to constructors, we don't have much
choice concerning the name, and sometimes, we do end up having
to have overloads where the choice made by overload resolution
affects the semantics of the code.
I suspect that this is at least part of the motivation for
"std::string( size_t, char )", as opposed to the what would seem
more intuitive to me "std::string( char, size_t = 1 )"; given
the latter, something like "std::string( NULL )" would be
legal... and create a string with a length of 1, which is
probably not what the author wanted. (The argument would be
even stronger if "std::string( (char const*)0 )" were a legal
means of creating an empty string.)
--
James Kanze GABI Software
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]