struct Node{
Node* parent; //null if it is root
Node* children; //0 - x
};
Futher I have ManagedObject class.
1 2 3 4 5 6 7 8 9 10 11
class ManagedObject{
private:
static Node* roots;
public:
virtualvoid* operatornew(size_t size){
//And here is problem. I need:
//a)If new is called for "main object" place new node into roots (parent == null)
//else b) if new is called for "member scope object" look for "main object"'s root node and set this node as its children.
}
};
My explanation is maybe chaotic so I show you example:
1 2 3 4 5 6 7 8 9
class A : public ManagedObject{
private:
ManagedObject* nestedObject;
public:
A(){
nestedObject = new ManagedObject;
}
};
in another part of program:
... ManagedObject* some = new A;
...
So new operator should place root node for "some" and simultaneously it should create node for "nestedObject" and set it as child of previous root node.