<js****@umich.eduwrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
: How do I compile with g++ version 4.0 so that a int will not be
: implcitly converted to a string.
There isn't actually such an implicit conversion, but ...
: for example...i would like the following code to result in an error
:
: int x = 4;
: string cat;
: cat = x;
This unfortunately "works" because std::string has
an assignment operator that accepts a single char.
So the last line is actually equivalent to:
cat.operator=( (char)x );
So the real problem here (other than the unfortunate
decision to provide this assignment op in the std lib)
is the implicit conversion from int to char .
Most compilers provide an option to issue a warning
when an implicit conversion results in the truncation
of an integer type. Please look up in your compiler's
doc, or as in a g++-dedicated forum (I don't have the
info for g++ here...)
hth -Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <
http://www.brainbench.com