简体   繁体   English

向量和迭代器的向量上的指针

[英]Pointer on vector of vector and iterator

I have a vector of vector of my object and I get a pointer of this vector. 我有一个对象向量的向量,并且得到了这个向量的指针。 My problem is I can't create an iterator with that. 我的问题是我不能用它创建一个迭代器。 This my code : 这是我的代码:

vector<vector<AbstractBlock*>> *vectorMap = _level->getMap()->getVectorMap();

for(vector<AbstractBlock*>::iterator i = vectorMap[colonneX-1].begin(); i < vectorMap[colonneX-1].end(); i++)
{
    /*some operations*/
}

It failed on vectorMap[colonneX-1].begin(), if the vectorMap is not a pointer I can do this 它在vectorMap [colonneX-1] .begin()上失败,如果vectorMap不是指针,我可以这样做

How I can make this? 我该怎么做?

Thanks! 谢谢!

Dereference vectorMap : 取消引用vectorMap

for(vector<AbstractBlock*>::iterator i = (*vectorMap)[colonneX-1].begin();
    i != (*vectorMap)[colonneX-1].end(); i++)

vectorMap is a pointer to a vector, not a vector. vectorMap是指向向量的指针,而不是向量。 They are two different things. 他们是两个不同的东西。 The pointer simply refers to the vector, they are not one in the same. 指针只是指向向量,它们不是同一位的。 You need to dereference vectorMap. 您需要取消引用vectorMap。

You mistake the number of indirection. 您误认为间接次数。 But there may be two different correct meaning. 但是可能有两种不同的正确含义。

if vectormap is a pointer, vectormap[x] is the x-th vectormap in an hypothetical vector<vector<AbstractBlock*>> array. 如果vectormap是一个指针, vectormap[x]是第x vectormap在一个假想的vector<vector<AbstractBlock*>>阵列。

I found strange that's what you mean, since it doesn't match the iterator type. 我发现这就是您的意思,因为它与迭代器类型不匹配。

But *vectormap is a vector<vector<...>> , (*vectormap)[x] is a vector<AbstractBlock*>> , whose iterator, if dereferenced twice, is an AbstractBlock . 但是*vectormap是一个vector<vector<...>>(*vectormap)[x]是一个vector<AbstractBlock*>> ,如果迭代两次,它的迭代器就是AbstractBlock

You most likely mean 你很可能是说

for(vector<AbstractBlock*>::iterator i = (*vectorMap)[colonneX-1].begin();
    i != (*vectorMap)[colonneX-1].end(); i++)
    (**i).abstractblock_methodcall();

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

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