I'm doing the bunny excersise thingy, and i want to have a bunnyEvent struct.
problem is, when i create it, it doesn't get initialized to 0 ? which is important because it contains a "turns" variable that obviously has to start at 0
as you can see, im creating a new BunnyEvent on the heap and then printing out the "turns" variable.
but it prints out some garbage value instead of 0?
The program doesn't know that you're expecting a zero. Make that zero a default value to your BunnyEvent (assumes non-obsolete compiler; prior to 2011 give it a constructor) or initialize it when it is created in the Bunny's constructor:
This could also be a good time to stop using new/delete: if you're creating an event in constructor and destroying it in the destructor of bunny, it should be simply a member of bunny.
It's not being initialized to 0 because you never initialize it to 0. If you called the default constructor used value initialization (thanks mbozzi), it would get initialized to the default value of 0, however.
ex: m_pBunnyEvent = new BunnyEvent;
becomes m_pBunnyEvent = new BunnyEvent();
In this case (where T is BunnyEvent), value-initialization means that the new object is zero-initialized, and that's it. Default-initialization simply calls the trivial default constructor, which does nothing.