简体   繁体   English

无法访问指针矢量地图元素,

[英]Cant access to a pointer-vector map element,

into my private section I have : 在我的私人部分中,我有:

vector<  vector<map<unsigned short int,col_data> > *> buffer_vectorS;
vector< map<unsigned short int,col_data> > * buffer_current;
map<unsigned short int,col_data> buffer_current_map;

( coldata is a simple structure: int, int, int, double ) (coldata是一个简单的结构:int,int,int,double)

Later I create a vector of map data, and save its pointer 稍后我创建一个地图数据向量,并保存其指针

vector<map<unsigned short int,col_data> > * buffer_vector = new vector<map<unsigned short int,col_data> >;
buffer_vectorS.push_back(buffer_vector);
buffer_current = buffer_vector;

Later I'd want to use the map element of the buffer_current to get-store data, 稍后,我想使用buffer_current的map元素来存储数据,

buffer_current_map = &buffer_current[index];

But this last does not compile.... I dont know how to write it... How can I access to an item of buffer_current? 但这最后一个不能编译...。我不知道如何编写...如何访问buffer_current项? Can you help me ? 你能帮助我吗 ?

Do you mean: 你的意思是:

buffer_current_map = (*buffer_vector)[index];

Be warned though, that will perform a copy operation on the map. 请注意,这将在地图上执行复制操作。 You might want to access the map using pointer semantics: 您可能想使用指针语义访问地图:

map<unsigned short int,col_data> *buffer_current_map;
buffer_current_map = &(*buffer_vector)[index];

Then no copy will be done. 然后将不进行任何复制。 Although, the pointer might be invalidated if a resize is done on the vector. 但是,如果对向量进行了调整大小,则指针可能会失效。

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

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