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开始不等于结束
基础教程推荐
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- CString 到 char* 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
