This is not exactly my code but it looks a lot like it
I have 2 tables of type CTable. They work in the same way as normal arrays but can be allocated dynamically and resized. So lets just pretend that they are arrays right now
One table has object references
MyObj obj1;
MyObj obj2;
MyObj table1[10];
table1[0] = obj1;
table1[1] = obj2;
Now because I want to order them differently sometimes, I've put pointers to these objects in another table
MyObj *table2[10];
table2[0] = &table1[0];
table2[1] = &table1[1];
Is there a way to get a reference to obj1 and obj2 through table2 so those object will get out of scope at the end of some kind of delete function
something like
void free() {
MyObj &obj = *table2[0];
}
and then bang, at the end of free, obj is delete automagically. Also, some kind of way to delete these objects through table2 would be acceptable.