3 ms·
Interestingly, here's what I get when I feed it your exact question: In C++, what happens when you call pop_back() on an empty vector? When you call p
by roel_v 4y ago
Interestingly, here's what I get when I feed it your exact question:
In C++, what happens when you call pop_back() on an empty vector?
When you call pop_back() on an empty vector in C++, an std::out_of_range exception is thrown. The pop_back() function removes the last element of a vector and it is undefined behavior to call it on an empty vector. Attempting to do so will result in the exception being thrown.
So it basically claims both that an exception is thrown, and that it's undefined behavior. At least in this case, one would know something is up.
- dpkirchner 4y agoI asked it again (in a new context) and got a partially right answer as well: > In C++, calling pop_back() on an empty vector results in an undefined behavior. An std::vector is a dynamic array that grows and shrinks automatically. pop_back() function is used to remove the last element of the vector. But if there are no elements in the vector, calling pop_back() will result in an error. Therefore, it is advisable to always check if the vector is empty before calling pop_back(). I wonder what sort of scores we would be seeing for each of these series of tokens (including those returned for roel_v). Is the aggregate score (for lack of a better term) higher for the initial reply I saw greater than the scores for these other replies?