比如有如下代码:
vector<int>::iterator tmp = find(box.begin(), box.end(), 0);
我想知道tmp保存的地址是多少,应该怎么做呢?
天蓬老师2017-04-17 14:30:57
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