the meaninings of two ** for an iterator
In the f开发者_运维问答ollowing 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 ?
The first * dereferences the iterator, giving a SceneObject * pointer. The second * dereferences this SceneObject * pointer to the SceneObject itself.
Because *iter is a SceneObject *& - a SceneObject pointer. You need to dereference it to get to the real SceneObject.
Because *iter returns a SceneObject* which will then be again dereferenced by the second *.
The first * returns the vale in the iterator, a SceneObject* pointer. The second * deferences that pointer, giving a SceneObject. I suspect there's an overload for << that renders the SceneObject` to a stream.
加载中,请稍侯......
精彩评论