为什么我可以从 (*iterator) 执行 operator&
,但无法复制值 (*iterator) ?
std::vector<int> v; // yes, container is empty
for (int i = 0; i < 10; ++i) {
auto it = v.begin();
std::cout << &*(it) << std::endl; // 0 <- why not EXC_BAD_ACCESS?
auto value = *(it); // EXC_BAD_ACCESS
auto address = &value;
}
最佳答案
v
为空,因此 v.begin() == v.end()
且取消引用 it
未定义。
关于c++ - std::vector、成员访问运算符和 EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74108118/