如果调用std :: vector :: begin()但将返回的迭代器分配给引用,会发生什么情况?它为什么起作用,迭代器值存储在哪里?
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?
这条线
auto& b = v.begin();
是一个错误,因为v.begin()返回一个临时变量,并且您不能将临时变量绑定到非const引用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句