Original Post
Hi Guys, Here is the thing.. Assume that we have 3 classes. ClassA, ClassB and ClassC. ClassB holds an array of pointers to ClassA created by new. and lets assume that I am using an accessor function to this pointer array, smtg like: And in ClassC, I want to get a hold to this pointer Array. So what I tried is to pass the pointer to ClassC from ClassB's accessor function(1). ClassC uses new to hold the incoming pointers in an array. Ok so far everything seems working. Here is my problem. I know that I cannot use delete, delete[] for my pointer array in ClassC. Because doing so result in deleting the ClassA objects in the heap, which is originally created by ClassB and suppose to live on after the destruction of ClassC. So what I did in ClassC is, instead of deleting the pointer array,I set all pointers in the array to NULL in the destructor. But does this approach in ClassC (after destruction of ClassC)free the memory that holds the pointers to ClassA created by ClassB ? Thanks in advance!
// This is in ClassB
ClassA** myPtr;
myPtr = new ClassA*[100];
//This is in ClassB (1)
ClassA* myPointer(void){return myPtr[index];}