gpt4 book ai didi

c++ - STL vector 、迭代器和插入 (C++)

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:20:30 27 4
gpt4 key购买 nike

我有一个向其传递 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com