Jump to content
  • Advertisement
Sign in to follow this  
ballack

problem using pointer to struct

This topic is 4877 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi everyone i have a structure like struct tank { ---- --- }*t[7]; but my game does not run when i use t[1]->member or t[1]->member etc it does not give any compilation error. can any one tell me why is this? should i use malloc or something?

Share this post


Link to post
Share on other sites
Advertisement
You declared an array of 7 pointers to the tank struct.
Did you actually fill that array with valid pointer?

Something along the line of:


// C++
for ( int i = 0; i < 7; ++i )
{
t = new tank();
}

// C
for ( int i = 0; i < 7; ++i )
{
t = (struct tank*)malloc( sizeof( struct tank ) );
}


Don't forget to delete (C++) or free (C) the array again!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!