I have an object called RobotData with, amongst others, the following data members,
Code:
int **PrevPosX;
int **CurPosX;
int **NextPosX;
int **PrevPosY;
int **CurPosY;
int **NextPosY;
The contructor for the object is here,
Code:
RobotData::RobotData (int a, int b):BotWidth (a), BotLength (b), velocity(0),direction(BotN),fRobotStatus(ROBOT_STATIONARY),MovementOverflow(0),fRobotTasked(NO_TASK_PRESENT),DistanceToStepsCovered (0),RobotHasMoved (0)
{
PrevPosX = new int* [a];
PrevPosY = new int* [a];
CurPosX = new int* [a];
CurPosY = new int* [a];
NextPosX = new int* [a];
NextPosY = new int* [a];
for (int i = 0; i < a; i++)
{
PrevPosX [i] = new int [b];
PrevPosY [i] = new int [b];
CurPosX [i] = new int [b];
CurPosY [i] = new int [b];
NextPosX [i] = new int [b];
NextPosY [i] = new int [b];
}
}
and the destructor is here,
Code:
RobotData::~RobotData()
{
for (int i = 0; i < BotWidth; i++)
{
delete [] PrevPosX [i];
delete [] PrevPosY [i];
delete [] CurPosX [i];
delete [] CurPosY [i];
delete [] NextPosX [i];
delete [] NextPosY [i];
}
delete [] PrevPosX;
delete [] PrevPosY;
delete [] CurPosX;
delete [] CurPosY;
delete [] NextPosX;
delete [] NextPosY;
}
The destructor is called when my programme receives the WM_DESTROY message (it's a windows app but I thought the problem was more C++ related so posted it here). My program closes and then I get the message telling me that an error has occured in my program. If I comment out the destructor then I get no error (not sure why that is, I thought windows implicity called your object destructors upon program closure if you had been too lazy to do it yourself).
Initially the arrays in this object were created as normal with global variables for the size. This was sloppy though so I changed it to dynamic allocation. Then the problems above occured so I think the problem is with this dynamic allocation. Can anyone spot any obvious errors?
Thanks