How to use method "SetUserData" of b2Body class ?

How to use method "SetUserData" of b2Body class ?
0.0 0


Hi !

My question is more a pure C*+ question or Box2D question but as I don’t know where to ask it…I ask it here !
I have got a *body of type b2Body and want to do something like this :
It doesn’t work as SetUserdata expects a “data” type.
Here is the iOS version which works:
NSNumber *number = ;
How to do the same in C
+ ?



This is a simple C*+ question and I’d suggest doing a little bit of research into the C*+ language. Here is an article on void pointers:

Here is a (non-portable) fix to your question above code:

_body->SetUserData( (void*) 2);

Another way would be to do something like this.

int* number = new int(2);

A more correct and portable way to set user data is to pack any data into a struct and pass a pointer from that struct.


Thanks a lot Kevin !

Just a question: what do you mean by “non portable” ? Thanks again.