Pointer Question with delete

Hey i have a question regarding pointers
i have a class
1
2
3
4
5
6
7
8
9
class MyClass
{
...
};

MyClass *c[50] = {NULL};

for( int i=0; i<50; i++ ) 
    c[i] = new MyClass( );

and i can access all the instances of c[]
by doing
for( int i=0; i<50; i++ )
c[i]->Something();

but now i need to delete for example c[10]
so i use
 
    delete c[10];

my question is how do i access all the other instance os c[]
is sequencial or not?
i want to use a for loop
but it cant check for the instances that was deleted
how can i do that???

was i clear?? i dont know how to explain properly

for example i want to use
1
2
for( int i=0; i<49; i++ ) 
    c[i]->Something();

but i dont want it to check for the deleted instance o c[], and there could be multiple deleted instances

plz any help or tips will do
You could do something like this:

1
2
delete c[10];
c[10] = NULL;

Then you can do the loop like this:

1
2
for(int i = 0; i < 50; ++i)
    if(c[i]) c[i]->Something();

Do notice that the array is still 50 elements long, so we need to go through elements from 0 to 49.
Last edited on
thanks =D
Topic archived. No new replies allowed.