Re: basic_string ctor
- From: "Stephen Howe" <stephenPOINThoweATtns-globalPOINTcom>
- Date: Thu, 19 May 2005 14:07:19 +0100
> They're not the same in C, which has no real concept of a string.
It most certainly does.
Admittedly it has limitations (can't have a string of '\0''s, strlen() is
O(N) not O(1), all memory managment of it is manual) but it has been like
that since the early days.
> In the (IME far more common) case where the distinction is merely an
artifact
> of C's poor string concept, I'd prefer the C++ library to simply accept 0
as
> an empty string.
It has nothin to do with C's poor string concept.
It has everything to do with the fact that NULL or 0 in pointer situations
is regarded as an invalid pointer for all types.
As shown in answer to Duane, you can make a valid pointer to an empty string
and a NULL pointer both construct a std::string as empty.
But if you fold this distinction in std::string's constructor, so NULL will
silently construct an empty std::string, then in the situation where the
pointer being NULL is an error in the program, this will silently pass over
this.
Stephen Howe
.
- Follow-Ups:
- Re: basic_string ctor
- From: Duane Hebert
- Re: basic_string ctor
- From: Carl Daniel [VC++ MVP]
- Re: basic_string ctor
- References:
- basic_string ctor
- From: John
- Re: basic_string ctor
- From: Carl Daniel [VC++ MVP]
- Re: basic_string ctor
- From: Duane Hebert
- Re: basic_string ctor
- From: Tom Widmer
- Re: basic_string ctor
- From: Carl Daniel [VC++ MVP]
- basic_string ctor
- Prev by Date: Re: basic_string ctor
- Next by Date: Re: basic_string ctor
- Previous by thread: Re: basic_string ctor
- Next by thread: Re: basic_string ctor
- Index(es):
Relevant Pages
|