Generally speaking, an iterator is a data structure that stores the real data address in an internal member variable and overloads various operators (such as the dereference operator *). To obtain the data address, the recommended method is &*, that is, first obtain the real data through the asterisk operator which may be overloaded by and then obtain the address.
But for vector<int>, it is actually typedef int *iterator, so even (int*)tmp is no problem.
You can refer to "STL Source Code Analysis" translated by Hou Jie
Generally speaking, an iterator is a data structure that stores the real data address in an internal member variable and overloads various operators (such as the dereference operator
*
). To obtain the data address, the recommended method is&*
, that is, first obtain the real data through the asterisk operator which may be overloaded by and then obtain the address.But for
vector<int>
, it is actuallytypedef int *iterator
, so even(int*)tmp
is no problem.You can refer to "STL Source Code Analysis" translated by Hou Jie
&*tmp is enough, or std::addressof(*tmp)