I keep staring, but it doesn't fix itself

Started by
5 comments, last by Trajar 24 years ago
Ok.. this may sound really easy, but I''ve stared at this for a long time (and you know what that does - nothing) So tell me what I''m doing wrong. I declare a ptr as TileClass * Map; in the include file. Later, I want to create a multi-dem. array out of it, so I do this Map = new TileClass[30][30]; for( i=0; i<=29; i++) { for( j=0; j<=29; j++ ) { TileClass * tempTile = new TileClass; tempTile->Init(1,0); Map[j] = tempTile; delete tempTile; } } And I get the error cannot convert from ''class TileClass (*)[30]'' to ''class TileClass * I know it something simple, yet staring doesn''t help...
Advertisement
The problem is that when you declare TileClass *Map; , you''re only creating ONE pointer, yet in your loop, you''re telling the compiler that *Map is an array. C++ don''t like that.
Solution : make it an array ''o pointers:

TileClass *Map[30];
Hey, I just answered this question in a different forum! You can go there to find out what I said b/c I don''t feel like posting again (and you should only post your questions to 1 forum )

Check out the GPI project today!
if I do understand you, you want to have 30x30 array of pointers pointing to TileClass objects.

but when you allocate new Tile (tempTile = new ...),
and you store the pointer to the array,
you immediatly delete the Tile (with delete tempTile),
so at the end you will get pointers pointing to nowhere
(i.e. to deleted objects) ...

that''s the second thing you are doing wrong.

---------------------------------------------------
Ped - Peter Helcmanovsky - 7 Gods demo group
http://7gods.rulez.sk
First Sight Entertainment - http://members.xoom.com/fseteam
---------------------------------------------------
---------------------------------------------------Ped - Peter Helcmanovsky - 7 Gods demo grouphttp://7gods.rulez.skFirst Sight Entertainment - http://members.xoom.com/fseteam---------------------------------------------------
This has already been covered here.


- null_pointer
Sabre Multimedia
TileClass **Map;

Map = new TileClass *[30];
for( i=0; i<=29; i++)
{
Map = new TileClass[30];
Map->Init(1,0);<br>delete []Map;<br>}<br><br>delete []Map;<br><br><br>That will initialize all the map, and then delete it. Basically, I don''t know why you would want to delete it at the same time as initializing it, but that''s what you were doing. That should work just fine, and you can access it like a two dimensional array.<br><br>Pythius </i>
"The object of war is not to die for your country, but to make the other bastard die for his"
Um. Just a guess, here. Is the error coming from the line:
Map[j]=tempTile;
?

If if is, then your problem is that you are trying to assign a single tile to a whole array of tiles. You should probably use:
Map [ j ]=tempTile;<br><br>Making friends one burger at a time.<br><br>Edited by - MartinJ on 4/11/00 3:03:55 PM <br><br>Edited by - MartinJ on 4/11/00 3:06:51 PM

This topic is closed to new replies.

Advertisement