How to use method "SetUserData" of b2Body class ?

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 :
<pre>
body~~>SetUserData;
</pre>
It doesn’t work as SetUserdata expects a “data” type.
Here is the iOS version which works:
<pre>
NSNumber *number = ;
_body~~>SetUserData;
</pre>
How to do the same in C
+ ?

Thanks

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:
http://www.learncpp.com/cpp-tutorial/613-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);
_body->SetUserData(number);

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.