"sqwirx" <sq****@dr.com> wrote in message
news:95**************************@posting.google.c om...
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