std::map, pointer to map key value, is this possible?

后端 未结 4 1422
悲&欢浪女
悲&欢浪女 2020-12-01 06:14
std::map myMap;

std::map::iterator i = m_myMap.find(some_key_string);
if(i == m_imagesMap.end())
            


        
4条回答
  •  伪装坚强ぢ
    2020-12-01 07:06

    If you're not sure which operations will invalidate your iterators, you can look it up pretty easily in the reference. For instance for vector::insert it says:

    This effectively increases the vector size, which causes an automatic reallocation of the allocated storage space if, and only if, the new vector size surpases the current vector capacity. Reallocations in vector containers invalidate all previously obtained iterators, references and pointers.

    map::insert on the other hand doesn't mention anything of the sort.

    As Pierre said, you should store the iterator rather than the pointer, though.

提交回复
热议问题