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.
有关参考,请参阅此答案.
相关文章