Article View: gnu.g++.help
Article #816Re: g++ 2.7.0: bool vs. string vs. const char* overloading
From: James Kanze US/ESC 60/3/141 #407...
Date: Fri, 03 Nov 1995 11:00
Date: Fri, 03 Nov 1995 11:00
48 lines
1857 bytes
1857 bytes
In article <199511021344.OAA02487@ssv4.dina.kvl.dk>
abraham@dina.kvl.dk (Per Abrahamsen) writes:
|> Can anyone explain to me why two doIt calls below select different
|> overloaded functions?
Compiler bug?
|> ------------- bug.C -------------
|> #include <iostream.h>
|> #include <string>
|> void doIt (string)
|> {
|> cout << "Gotta string\n";
|> }
|> void doIt (bool)
|> {
|> cout << "Gotta bool\n";
|> }
|> int main ()
|> {
|> const char* const cp = "Hi!";
|> doIt (cp);
Should call do( bool ), since a pointer converts to a bool implicitly
(and the conversion, which doesn't use any user defined conversions,
has precedence over the conversion to string, which involves calling
the constructor).
|> doIt ("Hi!");
Same as above.
|> return 0;
|> }
Rigorously speaking, it is an error. On the other hand, I can easily
imagine a compiler having an extension which allows literal string
constants (like "Hi!") to be treated exactly as strings (even up to
correctly initializing static memory for a string statically).
--
James Kanze Tel.: (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils en informatique industrielle --
-- Beratung in industrieller Datenverarbeitung
Technical Details
Message-ID:
<KANZE.95Nov3120054@slsv7xt.lts.sel.alcatel.de>Path:
arc1-ca.pugleaf.net!blackbush.xlink.net!slsv6bt!newsReferences:
<199511021344.OAA02487@ssv4.dina.kvl.dk>Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.help,comp.lang.c++ Path: arc1-ca.pugleaf.net!blackbush.xlink.net!slsv6bt!news From: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763) Subject: Re: g++ 2.7.0: bool vs. string vs. const char* overloading In-Reply-To: abraham@dina.kvl.dk's message of 2 Nov 1995 08:45:00 -0500 Message-ID: <KANZE.95Nov3120054@slsv7xt.lts.sel.alcatel.de> Sender: news@lts.sel.alcatel.de Organization: SEL References: <199511021344.OAA02487@ssv4.dina.kvl.dk> Date: 03 Nov 1995 11:00:53 GMT