Here is the quote from "Effective STL":
When you get an object from a container (via. e.g., front or back), what you set is a copy of what was contained. Copy in, copy out. That's the STL way.
I have had a hard time understanding this part. As far as I know front returns the reference of the first element (at least for std::vector).
Could you please explain above sentence?
This was actually an error in an earlier edition of the book. From the errata:
! 6/29/01 jk 20 The first para of Item 3 is incorrect: front 7/25/04
and back do NOT return copies of elements, they
return references to elements. I
removed all mention of front and back.
So the explanation of the sentence is: woops, time to get a new edition!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With