c++空std::vector开始不等于结束 [英] c++ empty std::vector begin not equals to end

查看:42
本文介绍了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开始不等于结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆