🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1752

Re: Why no conversion of string to const char * in STD lib?

#1752
From: Oren Ben-Kiki
Date: Sun, 20 Aug 1995 19:14
47 lines
2197 bytes
Distribution:
David Vandevoorde (vandevod@cs.rpi.edu) wrote:
: >>>>> "OB" == Oren Ben-Kiki <oren@melissa.schema.co.il> writes:
: In article <MATT.95Aug16093212@physics2.Berkeley.EDU>
: oren@melissa.schema.co.il (Oren Ben-Kiki) writes:
: Rick Hollinbeck (rickh@csn.net) wrote:

: Rick> From what I understand, the const char* conversion operator
: Rick> would trigger : too many implicit type conversions in certain
: Rick> situations, leading to many : unpleasant surprises. the c_str()
: Rick> member is a way to control this. (See : Plauger's recent article
: Rick> in the C/C++ Users Journal which discusses this.)

: OB> But now that we have the 'explicit' keyword, shouldn't this
: OB> decision be reconsidered? This seems like just the situation for
: OB> which it was intended.

: The `explicit' keyword is currently only applicable to constructors,
: not conversion operators.

Hmmm. At first I felt foolish for missing that, but on a second thought, why
is it so? Sometimes the choice between a constructor for one class and a
conversion operator for another is pretty arbitrary - and when the target
type is a built-in type, as in this case, the choice is made for you by the
compiler.

: Do you think:

:       f(static_cast<char*>(s))

: is more convenient than:

:       f(s.c_str())    ?

Point taken. I was thinking more of:

        f((char *)s)

But I guess that's just a bad habit left over from my C days.

                                                Oren.


---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <MATT.95Aug20111435@Austern>
Path: arc1-ca.pugleaf.net!overload.lbl.gov!agate!agate!Matt
References: <BASHFORD.95Aug1200815@toad.scripps.edu> <VANDEVOD.95Aug16144504@avs.cs.rpi.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!overload.lbl.gov!agate!agate!Matt
From: Oren Ben-Kiki <oren@melissa.schema.co.il>
Newsgroups: comp.std.c++
Subject: Re: Why no conversion of string to const char * in STD lib?
Date: 20 Aug 1995 19:14:35 GMT
Organization: <none>
Approved: Matt@Austern
Message-ID: <MATT.95Aug20111435@Austern>
References: <BASHFORD.95Aug1200815@toad.scripps.edu> <VANDEVOD.95Aug16144504@avs.cs.rpi.edu>
NNTP-Posting-Host: austern.hip.berkeley.edu