Operator overloading and copy constructor. Can't find the error.

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.
 
C

clicwar

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.

PS: I don't know why, but this is the 3rd time i try to post this
message.
 
V

Victor Bazarov

clicwar said:
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.

PS: I don't know why, but this is the 3rd time i try to post this
message.

Please stop, then. This is the third time I see it.
 
C

clicwar

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.

PS:I don't why, but this is the 3rd time i try to post this message.
 
C

clicwar

Please stop, then. This is the third time I see it.

Sorry Victor. I removed the messages.
And, James, about the book, that question was a bit precipitated.
I'm reading the reviews in http://www.accu.org/ and amazon and trying
to match one with my personality and time.
But thanks anyway.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top