"Grumble" <in*****@kma.eu .org> wrote in message
news:bp******** **@news-rocq.inria.fr.. .
| What, if any, is the difference between
|
| string s("toto");
| string s = "toto";
|
| In the first case, I am using the constructor:
|
| basic_string(co nst value_type *ptr);
|
| In the second case, I believe I first call another constructor:
|
| basic_string();
|
| and then operator= is executed...?
No, but this is a classic confusion.
What happens, in the second case, is that a temporary
may first be created to convert "toto" (the array of char)
into an std::string, and then the copy constructor will
be called, and the temporary destructed.
Many compilers will optimize-out the intermediate copy,
but the copy-constructor still has to be accessible.
By using the direct-initialization syntax, you
ensure that this intermediate copy will not occur.
See also, for some details and terminology:
groups.google.c om/groups?selm=bod 097%24iiv%241%4 0newshispeed.ch
hth -Ivan
--
http://ivan.vecerina.com