const int WORLD_WIDTH = 100;
const int WORLD_HEIGHT = 100;
CCell *m_cells[WORLD_WIDTH][WORLD_HEIGHT]; //cell data
m_width = WORLD_WIDTH;
m_height = WORLD_HEIGHT;
//allocate memory for the cells
for (int x = 0; x < m_width; x++)
{
for (int y = 0; y < m_height; y++)
{
if (rand() % 2 == 0)
m_cells[x][y] = new CLonerCell;
else
m_cells[x][y] = new CChattyCell;
}
}
thanks for the help
problem with 2d arrary of base class pointers
I have the base class CCell, and the derived classes CLonerCell, and CChattyCell. I am trying to make a 2d array of CCell pointers, but when i go to create the memory for each cell, i get a crash. here is some of the code.
Seems to work for me. What compiler are you using? Are you sure you don''t have any buffer overruns preceding the execution of this code that causes heap corruption? You aren''t doing any strange overloads on new, etc.?
well the code isn''t structure like that, m_cells belongs to the world class, but i wouldn''t think there would be any difference. i can''t seem to figure out what is going on.
The only thing I can suggest at this point then, is to try to create a minimal program that actually duplicates your problem. One way to do this is making a backup of your program and start removing what you think are irrelevant bits until it either stops crashing, at which point you''ve found a potential problem, or you don''t think there are any irrelevant bits left, in which case you can try sharing that with us.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement