C ++空std :: vector开始不等于结束 [英] c++ empty std::vector begin not equals to end
问题描述
我在Windows 10上遇到的情况是,声明了空的类成员变量向量,但是此向量的 begin()(第一个迭代器)
和 end()(最后一个迭代器)
不同,正如我所知道的,在空向量中,这2个应该相同.有任何想法吗?:)))
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()
{
}
在构造函数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开始不等于结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!