I’m not very familiar with C++ programming. I know the basics of programming in it (syntax, pointers, etc.) and I’ve built a few basic programs with it and done some basic debugging at work. I am puzzled by this line of code from Box2D, specifically the Box2dTest project from Cocos2D:
// Define the ground body.
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0, 0); // bottom-left corner
How is it that one can do this without having initialized groundBodyDef? I know this isn’t an Objective-C thing because the C++ examples for Box2D itself are just like this.
groundBodyDefactually is initialized!I think you expected something along the lines of:
which is actually still valid, but it is initialized on the heap. In your version,
groundBodyDefis initialized on the stack, much like you would initialize aninton the stack.As it is called without parameters, the default constructor is used.