Class and pointer to pointer
Hi!
I have a few questions about ** (pointer to pointer).
Let's say I have a class named Activity.
I would code it like this ...
Code:
int tableLength = 3; // 2 from before and 1 new
Activity **newTable = new Activity*[tableLength]; // 3 activities in newTable => is this correct?
// now add old activities into a new table
for (int i = 0; i < tableLength - 1; i++)
{
Activity *act = getActivity(i); // getActivity(i) returns Activity*
memmove(newTable[i], act, sizeof(Activity*)); // is this correct?
// is this correct =>> newTable[i] = act;?
delete []act; // is this correct?
act = NULL;
}
// and add a new one
memmove(newTable[tableLength - 1], act, sizeof(Activity*)); // is this correct?
// some code where I use the newTable
// and than free - is this correct?
for (int i = 0; i < tableLength; i++)
{
delete []newTable[i];
newTable[i] = NULL;
}
delete []newTable;
newTable = NULL;
So, please take a look at the code and tell me what am I doing wrong.
Thanks!