I mistakenly took the address of the reference returned by the back() operator in an empty container and was surprised to see that the address wasn’t zero.
If a container e.g. std::deque is empty, what does back() return?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
it returns the last element.
on this page: http://www.sgi.com/tech/stl/BackInsertionSequence.html
precondition: !a.empty()
Equivalent to *(–a.end()).
since the precondition is the deque is not empty, then it means it’s undefined behavior.