Jump to content
  • Advertisement
Sign in to follow this  

Dynamic Array of Structs

This topic is 5465 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

I can't figure out what is wrong with this code:
struct MAPTILE {
    int x;
    int y;
    int collisionLayerOne;
    int collisionLayerTwo;
    int animLayerOne;
    int animLayerTwo;
    char layerone[80];
    char layertwo[80];

MAPTILE *maptiles = new MAPTILE[1];  // dummy 

maptiles[0]->y = 0;
maptiles[0]->x = 0;
maptiles[0]->collisionLayerOne = 0;
maptiles[0]->collisionLayerTwo = 0;
maptiles[0]->animLayerOne = 0;
maptiles[0]->animLayerTwo = 0;
maptiles[0]->layerone = "NONE";
maptiles[0]->layertwo = "NONE";

I'm getting the following error: syntax error before `->' token [all of them] I've been working on this for a few hours now so I'm probably just missing something really obvious... but I don't see anything wrong with this code!

Share this post

Link to post
Share on other sites
maptiles may be of type MAPTILE*, but maptiles[0] isn't, because the [0] states to dereference the pointer to the first element in the array.

Change "->" to "." as mentioned beforehand.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!