C
clicwar
The details are simple: the standard says that an implementation
may copy, even if it doesn't make sense, and the standard
requires that the value being assigned by copiable, even if
there's absolutely no need for a copy in reality.
Never. Imagine that d had a pointer to dynamically allocated
memory. Are you saying that the compiler should be allowed to
copy construct into that memory, overwriting the pointer to
dynamically allocated memory (and thus creating a memory leak).
There are two absolute invariants in the language: an object is
constructed exactly once, and it is destructed exactly once.
The compiler will never, ever generate a call to a constructor
on an already constructed object. (Barring compiler errors, of
course, but such errors have become very, very rare.)
The problem has nothing to do with the creation of the
temporary. The problem is binding the temporary to the
reference parameter of operator=.
--
James Kanze (GABI Software) email:[email protected]
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 >34
I finally can make the logic connections in my mind.
Thankyou very much, James and all the others who spent their valuable
time in this topic.
James, just one more question: Could you recommend me a book/tutorial/
site which teaches c++ using this deeper approach, or such book does
not exist, at least not for the beginner public.