I am allocating with new and I knew that I should be freeing the memory as I remove elements of the array. I tried it with the delete after the if statement and I get an abnormal program termination. MSVC++6.
Code:
switch(p)
{
case 1:for(i=0;i<count;i++)
if(typeid(*people[i])==typeid(Student))
{
delete people[i];
for(j=i;j<=count-1;j++)
people[j]=people[j+1];
count--;
}break;
case 2:for(i=0;i<count;i++)
if(typeid(*people[i])==typeid(Teacher))
{
delete people[i];
for(j=i;j<=count-1;j++)
people[j]=people[j+1];
count--;
}break;
case 3:for(i=0;i<count;i++)
if(typeid(*people[i])==typeid(Manger))
{
delete people[i];
for(j=i;j<=count-1;j++)
people[j]=people[j+1];
count--;
}break;
}
This is basically what I am trying to do(above). I have gotten it to work to remove one type without using delete. But say after removing all students, I want to go back in and remove all teachers.....that's just not happening for me. I have drawn this out several times and on paper it seems like it should work just fine. Any ideas on what I am doing wrong here?