开发者

Referring to the address of a collection element via iterators

开发者 https://www.devze.com 2023-02-11 15:02 出处:网络
How can I refer to the address of an element in a vect开发者_JS百科or using iterators. vector<Record>::const_iterator iter = collectionVector.begin();

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

精彩评论

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