Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


I keep staring, but it doesn't fix itself

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

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...

Share this post

Link to post
Share on other sites
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];

Share this post

Link to post
Share on other sites
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
First Sight Entertainment - http://members.xoom.com/fseteam

Share this post

Link to post
Share on other sites
TileClass **Map;

Map = new TileClass *[30];
for( i=0; i<=29; i++)
Map = new TileClass[30];
delete []Map[i];

delete []Map;

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.


Share this post

Link to post
Share on other sites
Um. Just a guess, here. Is the error coming from the line:

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 [ i ][ j ]=tempTile;

Making friends one burger at a time.

Edited by - MartinJ on 4/11/00 3:03:55 PM

Edited by - MartinJ on 4/11/00 3:06:51 PM

Share this post

Link to post
Share on other sites

  • 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!