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

  • Home
  • SEARCH
  • 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 7529189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:35:35+00:00 2026-05-30T04:35:35+00:00

I create this struct: struct MyBodyData { int someNumber; }; and then created a

  • 0

I create this struct:

struct MyBodyData
{
    int someNumber;
};

and then created a new body:

b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(0.0f, -10.0f);
b2Body* body1 = world->CreateBody(&bodyDef);
MyBodyData *bodyData = new MyBodyData();
bodyData->someNumber = 4;
body1->SetUserData(&bodyData);

b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(.5f, .5f);//These are mid points for our 1m box
b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox; 
fixtureDef.density = 1.0f;
fixtureDef.friction = 0.3f;
body1->CreateFixture(&fixtureDef);

And then tried to access someNumber here:

for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
{
    CCLOG(@"Hello One");
    MyBodyData* data = (MyBodyData*)b->GetUserData();
    if (data!=0 && data->someNumber != 0)
    {
        int temp;
        temp = data->someNumber;
        CCLOG(@"Hello Again! %d",temp);
    }
}

It displays someNumber as a memory address 6-7 digits long instead of the value “4”.

What am I missing?

  • 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-05-30T04:35:37+00:00Added an answer on May 30, 2026 at 4:35 am
    body1->SetUserData(&bodyData);
    

    You’re setting the body data to be the address of the pointer bodyData. You don’t want that, you want to set it to bodyData. So:

    body1->SetUserData(bodyData);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a type list. I then create a class using a template
i need to create a data type (struct in this case) with an array
struct inode_operations ext3_dir_inode_operations = { .create = ext3_create, .lookup = ext3_lookup, } This struct
Let's suppose I have a struct like this: struct my_struct { int a; int
Suppose I have a struct containing a std::string, like this: struct userdata{ int uid;
I have a data structure like this: struct foo { int id; int route;
I have a interface documented like this: typedef struct Tree { int a; void*
I created a structure like this typedef struct Node { NSString* Description; NSString* AE;
In c++ if you create a struct or class like this struct foo {
They can be defined like this Struct.new(:x, :y) But what can usefully be done

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.