我有一个向其传递 vector 迭代器的方法。 在这种方法中,我想将一些元素添加到 vector 中,但我不确定在只有迭代器时这是否可行
void GUIComponentText::AddAttributes(vector<GUIComponentAttribute*>::iterator begin, vector<GUIComponentAttribute*>::iterator end)
{
for (vector<GUIComponentAttribute*>::iterator i = begin; i != end; ++i)
{
GUIComponentAttribute &attrib = *(*i);
// Here are the GUIComponentAttribute objects analyzed - if an object of a
// special kind appears, I would like to add some elements to the vector
}
}
谢谢 马库斯
最佳答案
在您显示的代码中,这是不可能的。特别是因为在迭代 vector 时不应向 vector 添加元素或从 vector 中删除元素。
关于c++ - STL vector 、迭代器和插入 (C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8255398/