c++ - How to know if a std::list has been modified -
possible duplicate:
create std::list of value instead of std::list of pointers in recursive function
i have class:
class c { public: c* parent; std::list<c> children; };  i can use class in way example:
c root; c child; root.children.push_back(child); // or other method of std::list (es: push_front, insert, ...) // here child.parent root // how can set parent of child?  i want work internally class without losing functionality of std::list, possible?
if understanding question correctly, want this:
class c { public: c* parent; std::list<c *> children; explicit c(c *p = 0) : parent(p) { if (p) p->children.push_back(this); } }; c root; c child(&root);  note changed children list take pointers. fine long c not expected manage memory nodes, refer them.
the title of question was: how know if std::list has been modified. comments, seems want proxy:
class listproxy { std::list<c *> children; public: // replicate list traits // ... void push_back (c *c) { children.push_back(c); //... } void erase (iterator i) { children.erase(i); //... } //... };  the proxy delegates list functionality list, augments behavior methods change list.
class c { public: c* parent; listproxy children; explicit c(c *p = 0) : parent(p) { if (p) p->children.push_back(this); } };  
Comments
Post a Comment