指针向量的迭代器未正确解引用 [英] Iterator for vector of pointers not dereferencing correctly
本文介绍了指针向量的迭代器未正确解引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的问题:
我有一个 std::vector
用于跟踪子控件.
I have a std::vector<AguiWidgetBase*>
which is used to keep track of child controls.
我有这两个函数来返回迭代器:
I have these two functions to return iterators:
std::vector<AguiWidgetBase*>::const_iterator AguiWidgetBase::getChildBeginIterator() const
{
return children.begin();
}
std::vector<AguiWidgetBase*>::const_iterator AguiWidgetBase::getChildEndIterator() const
{
return children.end();
}
然后我像这样使用它:
for(std::vector<AguiWidgetBase*>::const_iterator it = box->getChildBeginIterator();
it != box->getChildEndIterator(); ++it)
{
it->setText("Hello World");
}
我收到这些错误:
Error 3 error C2039: 'setText' : is not a member of 'std::_Vector_const_iterator<_Ty,_Alloc>' c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\main.cpp 112
Error 2 error C2839: invalid return type 'AguiWidgetBase *const *' for overloaded 'operator ->' c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\main.cpp 112
为什么会出现这些错误?
Why is it giving me these errors?
谢谢
推荐答案
有什么方法可以改变我的迭代器,让它-> 工作吗?
Is there a way I can change my iterators so that it-> works?
不是直接的,但你可以这样做:
Not directly, but you could do something like:
for(std::vector<AguiWidgetBase*>::const_iterator it = box->getChildBeginIterator();
it != box->getChildEndIterator(); ++it)
{
AguiWidgetBase* p = *it;
p->setText("Hello World");
}
这篇关于指针向量的迭代器未正确解引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文