Article View: gnu.g++.help
Article #814Re: g++ 2.7.0: bool vs. string vs. const char* overloading
From: Alex Martelli
Date: Thu, 02 Nov 1995 22:52
Date: Thu, 02 Nov 1995 22:52
28 lines
1490 bytes
1490 bytes
abraham@dina.kvl.dk (Per Abrahamsen) writes:
...
>Can anyone explain to me why two doIt calls below select different
>overloaded functions?
...
>void doIt (string)
...
>void doIt (bool)
...
> const char* const cp = "Hi!";
> doIt (cp);
> doIt ("Hi!");
There is no conversion from a const char* to a non-const string,
while there is one from any pointer to bool, so the first call
will surely end up calling doIt(bool). The literal "Hi!" is
a (non-const) char* (for historical reasons) -- I confess I'm
not sure why the user-defined conversion to string is
unambiguously preferred to the builtin one to bool (perhaps
the latter would have to go through a _const_ char*...?)
Alex
--
DISCLAIMER: these are TOTALLY personal opinions and viewpoints, NOT connected
in any way with my employer, nor any other organization or individual!
Email: martelli@cadlab.it Phone: +39 (51) 597313
CAD.LAB s.p.a., v. Ronzani 7/29, Casalecchio, Italia Fax: +39 (51) 597120
Technical Details
Message-ID:
<martelli.815352732@cadlab>Path:
arc1-ca.pugleaf.net!sirio.cineca.it!cadlab!martelliReferences:
<199511021344.OAA02487@ssv4.dina.kvl.dk>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sirio.cineca.it!cadlab!martelli From: martelli@cadlab.cadlab.it (Alex Martelli) Newsgroups: gnu.g++.help,comp.lang.c++ Subject: Re: g++ 2.7.0: bool vs. string vs. const char* overloading Date: Thu, 2 Nov 1995 22:52:12 GMT Organization: Cad.Lab Spa, Bologna, Italia Sender: news@cadlab.it Message-ID: <martelli.815352732@cadlab> References: <199511021344.OAA02487@ssv4.dina.kvl.dk> NNTP-Posting-Host: dsslb.cadlab.it X-Newsreader: NN version 6.5.0 #11