迭代器中两个 ** 的含义
在下面的代码段中
vector<SceneObject *> sceneObjs;
vector<SceneObject *>::iterator iter;
iter = sceneObjs.begin();
while (iter != sceneObjs.end()){
cout << **iter <<endl;
iter++;
}
为什么 **iter 有两个 * ?
In the following code segment
vector<SceneObject *> sceneObjs;
vector<SceneObject *>::iterator iter;
iter = sceneObjs.begin();
while (iter != sceneObjs.end()){
cout << **iter <<endl;
iter++;
}
why **iter has two *s ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
第一个 * 取消引用迭代器,给出一个
SceneObject *
指针。第二个 * 取消引用此SceneObject *
指针到SceneObject
本身。The first * dereferences the iterator, giving a
SceneObject *
pointer. The second * dereferences thisSceneObject *
pointer to theSceneObject
itself.因为
*iter
是一个SceneObject *&
- 一个SceneObject
指针。您需要取消引用它才能获得真正的SceneObject。Because
*iter
is aSceneObject *&
- aSceneObject
pointer. You need to dereference it to get to the realSceneObject
.因为
*iter
返回一个SceneObject*
,然后它会再次被第二个*
取消引用。Because
*iter
returns aSceneObject*
which will then be again dereferenced by the second*
.第一个
*
返回迭代器中的值,即一个SceneObject*
指针。第二个*
引用该指针,给出一个SceneObject
。我怀疑将 SceneObject` 渲染到流的<<
存在重载。The first
*
returns the vale in the iterator, aSceneObject*
pointer. The second*
deferences that pointer, giving aSceneObject
. I suspect there's an overload for<<
that renders the SceneObject` to a stream.