Kevin Goodsell wrote:
[snip]
Assignment operator?
No assignment operator is used in that context - the syntax just happens
to look similar. What is actually invoked is the copy constructor, after
first converting the initializer to the appropriate type. Alternatively,
an implementation is explicitly allowed to eliminate the copy
constructor call and initialize directly from the initializer.
[snip]
Hmm.. I would've though that if there was no implicit conversion then
the compiler would use the assignment operator (if present). That would
make sense to me. Unfortunately, my compiler seems to agree with you.
[snip]
The relationship between a string ADT and the 'string' data format that
the language uses is close enough that it would be difficult to find a
good reason to disallow this implicit conversion. But suppose the class
was BigInt, which can be constructed from a string of digits. An
implicit conversion from an arbitrary string in this case could result
in unpleasant surprises.
[snip]
This whole issue seems kind of impractical to me. I can't remember the
last time I used that syntax to create an object -- looking at my code I
just seem to use:
String str( "whatever" );
Which I (now) think is probably good practice.
-- Pete
.