c++ empty std::vector begin not equals to end(c++空std::vector开始不等于结束)
问题描述
您好,我在 Windows 10 上遇到了一种情况,它声明了空的类成员变量向量,但是这个向量的 begin()(first iterator)
和 end()(last iterator)
不同,正如我在空向量中所知道的那样,这两个应该是相同的.有任何想法吗?:)))
Hi I have situation on windows 10, that declared empty class member variable vector, but this vector's begin()(first iterator)
and end()(last iterator)
differ, as I know in empty vector those 2 should be same. Any ideas? :)))
struct B
{
std::string a;
std::string b;
};
class A
{
A();
std::vector<B> vec_;
};
A::A()
{
}
在构造函数中 vec_.begin().base()
不等于 vec_.end().base()
Here in costructor A vec_.begin().base()
not equals vec_.end().base()
据我所知应该是相等的
推荐答案
标准只要求迭代器相等,不要求它们的地址相同.考虑迭代器的地址是没有意义的.
The standard only requires that the iterators are equal, not that their adresses are the same. Considering the adresses of iterators is pointless.
正如其他人所说,这两个迭代器是不同的对象,因此它们需要具有不同的地址.
As other have stated, the two iterators are different objects, so they need to have different adresses.
有关参考,请参阅此答案.
这篇关于c++空std::vector开始不等于结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:c++空std::vector开始不等于结束


- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 从python回调到c++的选项 2022-11-16
- Stroustrup 的 Simple_window.h 2022-01-01
- 静态初始化顺序失败 2022-01-01
- C++ 协变模板 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01