What happens if std::vector::begin() is called but the returned iterator is assigned to a reference? Why does it work and where is the iterator value stored?
std::vector<int> v;
auto a = v.begin(); //I assume iterator is stored on the stack in variable "a".
auto& b = v.begin(); //What happens here?
This line
auto& b = v.begin();
is an error, because v.begin() returns a temporary, and you can't bind a temporary to a non-const reference.
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