how copy the first elements of pair in vector to another vector?

前端 未结 2 1035
时光取名叫无心
时光取名叫无心 2021-01-25 13:49

I have a std::vector with element of the type std::pair. With some algorithm, I return two iterators (range) so I would like to pick up all elements within that range and copy t

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-25 13:52

    It's because of the operator precedence. The select operator . has higher precedence than the dereference operator *.

    So what the compiler thinks you're writing is

    *(it1.first)
    

    when you mean

    (*it1).first
    

提交回复
热议问题