开发者

Referring to the address of a collection element via iterators

How can I refer to the address of an element in a vect开发者_JS百科or using iterators.

vector<Record>::const_iterator iter = collectionVector.begin();
while(iter != collectionVector.end())
{

//How can I refer to the address of a Record here
function(...); //accepts &Record type

}


You can use the &(*iter) to get the address. Here is a sample code:

    std::vector<int> a;
    a.push_back(1);
    std::vector<int>::iterator iter = a.begin();
    int *p = &(*iter) ;
    *p =10;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜