Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7970685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:27:21+00:00 2026-06-04T07:27:21+00:00

I am trying to write an iPhone game using cocos2d and Box2D, which means

  • 0

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.

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

std::vector<LevelObject*>* levelObjects;

The LevelObject class contains the sprite, b2bodyDef and so on, all pointers as well.

The problems started when I wanted to iterate through this vector when I wanted to draw a level. The code I wrote was this:

-(void)startLevel:(b2World*) world withLevel:(GameLevel*) level{
std::vector<LevelObject*>::iterator it;
for (it = level->getLevelObjects()->begin() ; it != level->getLevelObjects()->end(); ++it) {
    CCSprite* sprite = it->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->

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?

Thanks 🙂

EDIT: getLevelObjects() are:

std::vector<LevelObject*>* getLevelObjects(){return levelObjects;}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:27:23+00:00Added an answer on June 4, 2026 at 7:27 am

    Your iterators point to pointers, so you need two dereferences:

    (*it)->sprite
    

    the dereference of the iterator,

    *it
    

    gives you a LevelObject*.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write my first iPhone app, and I'm using a date picker
I'm writing an iPhone game and I am trying to write some requirements documents.
I am trying to write an iPhone app using Delphi XE2 / FireMonkey and
I'm trying to write an iPhone application, and I have a problem. I have
Greetings, I'm trying to write my first iPhone app. I have the need to
I'm trying to write an iPhone app in which the user can register for
Hi I'm trying to learn how to write apps for the iPhone. I'm using
I'm very new to iPhone development, and I'm trying to write a function which
I'm trying to write two applications (iphone and desktop) to achieve what's been described
I'm trying to write an SSH client for the iPhone, and I'd like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.