Dynamic Array of Structs

Started by
3 comments, last by ontheheap 19 years, 6 months ago
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!
Advertisement
"->" should be "." ?
I'm pretty sure I need the -> operator because maptiles is a pointer to type MAPTILE.
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.
Thanks guys =)

This topic is closed to new replies.

Advertisement