I'm writing a class that holds a pointer to a parent object of the same type (think Qt's QObject system). Each object has one parent, and the parent should not be destroyed when a child is destroyed (obviously).
class MyClass
{
public:
MyClass(const MyClass* ptr_parent): parent(parent){};
~MyClass(){ delete[] a_children; };
private:
const MyClass* ptr_parent; // go to MyClass above
MyClass* a_children; // go to MyClass below
size_t sz_numChildren; // for iterating over a_children
}
(Excuse my inline coding, it's only for brevity)
Will destroying the "Master MyClass" take care of all children? No child should be able to kill it's parent, because I would then have pointers in my main program to destroyed objects, correct?
Why might you ask? I need a way to "iterate" through all subdirectories and find all files on a platform independent level. The creation of this tree will be handled by native API's, the rest won't. Is this a good idea to start with?
Thanks!