replacing c_str with operator asterix



 DEVELOP > c-Plus-Plus > replacing c_str with operator asterix

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "sqwirx"
Date: 20 Dec 2003 10:14:20 PM
Object: replacing c_str with operator asterix
I am using a String that has a member function c_str(). Because I
think c_str() reduces the readability of the code and I don't want
implicit conversions, I'm concidering to add a "char const *
operator*()". When you look at String as a fancy char* smartpointer
then it makes perfectly sense to dereference it with operator*.
What you think of it?
.

User: "Peter van Merkerk"

Title: Re: replacing c_str with operator asterix 21 Dec 2003 12:17:27 PM
"sqwirx" <sqwirx@dr.com> wrote in message
news:954b2fab.0312202014.4ad505c3@posting.google.com...

I am using a String that has a member function c_str(). Because I
think c_str() reduces the readability of the code and I don't want
implicit conversions, I'm concidering to add a "char const *
operator*()". When you look at String as a fancy char* smartpointer
then it makes perfectly sense to dereference it with operator*.

What you think of it?

I agree with Cy, this not a good idea; even many alternative string classes
have a c_str() member. Inventing your own conventions won't make your code
clearer to other people. Unintuitive operator overloading only obfuscates
your code. So personnaly I'd stick with the standard conventions.
I have seen string classes with implicit conversion operators to const char*
(e.g. MFC's CString class) so you could write:
CString str = "Hello";
const char* ptr = str;
Those type conversion operators may seem appealing at first, but classes
with type conversion operators can yield unexpected results. So I tend to
avoid those to.
--
Peter van Merkerk
peter.van.merkerk(at)dse.nl
.

User: "Cy Edmunds"

Title: Re: replacing c_str with operator asterix 20 Dec 2003 10:43:43 PM
"sqwirx" <sqwirx@dr.com> wrote in message
news:954b2fab.0312202014.4ad505c3@posting.google.com...

I am using a String that has a member function c_str(). Because I
think c_str() reduces the readability of the code and I don't want
implicit conversions, I'm concidering to add a "char const *
operator*()". When you look at String as a fancy char* smartpointer
then it makes perfectly sense to dereference it with operator*.

What you think of it?

You can hire thousands of programmers who will immediately understand
std::string::c_str(). Who is going to understand String::operator * ()?
--
Cy
http://home.rochester.rr.com/cyhome/
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER