简体   繁体   English

复杂数据类型的向量的迭代器

[英]Iterator for a vector of complex data type

I have a structure like below 我有一个像下面的结构

struct voxelParam
{
int voxelID;
int paramID;
}

and I have a vector of the structure 我有一个结构的向量

std::vector<voxelParam*> &finalist;

I want to navigate through the vector using iterators 我想使用迭代器浏览矢量

for (std::vector<voxelParam*>::iterator it = finalList.end(); it != finalList.begin(); --it)
{
    //I want to get 'it->voxelID' but that is not the way to do it.   
}

How do I access the voxelID part using the iterator defined 如何使用定义的迭代器访问voxelID部件

Use (*it)->voxelID instead. 使用(*it)->voxelID代替。

Note that finalist is a reference of a vector of voxelParam pointers . 需要注意的是finalist是的基准 vectorvoxelParam 指针 So *it gives the value at the iterator which is voxelParam* , which is then used to access the members via -> . 因此, *ititerator处给出的值是voxelParam* ,然后用于通过->访问成员。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM