gpt4 book ai didi

c++ - 将 vector 的 end() 传递给 std::vector::erase 有效吗?

转载 作者:行者123 更新时间:2023-11-30 04:14:41 24 4
gpt4 key购买 nike

一个非常简单的问题,但我找不到答案。允许它但要仔细检查是非常有意义的。

std::vector<int> v(10, 0);
v.erase(v.end()); // allowed or not?

最佳答案

无效的位置或范围会导致未定义的行为。

来自 here

The iterator pos must be valid and dereferenceable. Thus the end() iterator (which is valid, but is not dereferencable) cannot be used as a value for pos.

关于c++ - 将 vector 的 end() 传递给 std::vector::erase 有效吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18771368/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com