Values ​​of two ** for iterator

In the next 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?

+4
source share
4 answers

The first * dereferences the iterator by specifying a SceneObject * pointer. The second * splits this SceneObject * pointer SceneObject * itself.

+12
source

Because *iter is a pointer to SceneObject *& - a SceneObject . You need to play it to get to the real SceneObject .

+11
source

Because *iter returns a SceneObject* , which will then be dereferenced by the second * .

+5
source

The first * returns vale in the iterator, a SceneObject* pointer. The second * pointer deactivation giving SceneObject . I suspect that there is an overload for << that maps SceneObject` to the stream.

+3
source

All Articles