c++ empty std::vector begin not equals to end

前端 未结 3 1878
伪装坚强ぢ
伪装坚强ぢ 2021-01-29 16:33

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)

3条回答
  •  忘掉有多难
    2021-01-29 17:26

    The iterators are returned by value, so the address will indeed not be the same. Even if you do:

    const vector::iterator &it1 = vect.begin();
    const vector::iterator &it2 = vect.begin();
    

    the addresses of it1 and it2 can be different (and will be in many implementations) - even if references are used.

    (note that using begin() in both is not a mistake - the same method begin() will return two different objects with different values)

提交回复
热议问题