I want to append a new value to a c++ std::vector and this new value is relative to the last value in the vector. Can this code result in undefined behaviour?
std::vector<int> vector;
vector.push_back(1);
vector.push_back(vector.back() + 1);
I want to append a new value to a c++ std::vector and this new value is relative to the last value in the vector. Can this code result in undefined behaviour?
std::vector<int> vector;
vector.push_back(1);
vector.push_back(vector.back() + 1);
The vector
isn't empty, so you're not invoking undefined behavior because of that.
The parameter to push_back
is fully evaluated before the call is made, so that's not undefined behavior either.