title: Iterating through a pointer to a vector of pointers
body: <p>I am trying to write an iPhone game using cocos2d and Box2D, which means I have to mix between Objective-C and C++. I have a question regarding using pointers to objects of gameLevels and levelObjects that I have created.</p>
  
  <p>I have a class called GameLevel which contains a vector of levelObjects. I thought that using pointers was the way to do it, to make sure I use as little memory as possible. That means that my vector is</p>
  
  <pre><code>std::vector&lt;LevelObject*&gt;* levelObjects;
  </code></pre>
  
  <p>The LevelObject class contains the sprite, b2bodyDef and so on, all pointers as well.</p>
  
  <p>The problems started when I wanted to iterate through this vector when I wanted to draw a level. The code I wrote was this:</p>
  
  <pre><code>-(void)startLevel:(b2World*) world withLevel:(GameLevel*) level{
  std::vector&lt;LevelObject*&gt;::iterator it;
  for (it = level-&gt;getLevelObjects()-&gt;begin() ; it != level-&gt;getLevelObjects()-&gt;end(); ++it) {
      CCSprite* sprite = it-&gt;sprite; //Here XCode complaints about "Member reference base type 'LevelObject *' is not a structure or union" and "Use of undeclared identifier 'sprite'". I cannot seem to access any of the objects variables/methods from it-&gt;
  </code></pre>
  
  <p>So the question I ask is: Is this a good way to to this, with a pointer to vector of pointers? And why doesn't the iteration work?</p>
  
  <p>Thanks :)</p>
  
  <p>EDIT: getLevelObjects() are:</p>
  
  <pre><code>std::vector&lt;LevelObject*&gt;* getLevelObjects(){return levelObjects;}
  </code></pre>