CPB Mailing List

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The damnedest problem?!?!?



Michael,

I don't mean to insult you, but i believe you are wrong on two counts...

First, AnsiString only has a single operator=() function; I can find no
overloaded operator=() that can convert an int to a string (see dstring.h).  The
assignment works because there is a constructor for AnsiString which accepts an
integer parameter.

Second, in the following code, 

  int i = 0;
  AnsiString s;
  s = i + 1;

You said it yourself "The right hand side of the assignment needs to be resolved
first." - There is no AnsiString on the rhs.
The rhs of the assignment is evaluated before the assignment to string. There is
no need for anything but integer math on the rhs.  No "overloaded + operator",
nothing.

I do this kind of thing frequently, without error.
The statement is essentially an implicit typecast:

s = (AnsiString)( i + 1);

with no real weirdness going on what-so-ever.

hth,
giles

Michael Trier wrote:
>
> Although the AnsiString does have an overloaded = operator that will
> convert an int to a string, in this case it does not apply.  The
> right hand side of the assignment needs to be resolved first.  This
> means that the int must support adding an int and a String (not
> possible) or the AnsiString must have an overloaded + operator that
> allows adding an int to a String.  AnsiString only overloads the +
> operator to support an AnsiString + AnsiString syntax or a char* +
> AnsiString syntax.  I'm with Lanny on this one.
>


W Komornicki's Home Page | Main Index | Thread Index