c++ - Dealing with circular inclusion in a parent/child class relationship -
assume i've made class, parent, has composition relation child. parent class holds list of children.
i want children hold reference parent, every child holds parent pointer.
this cause circular inclusion. refer child in parent.h , refer parent in child.h. therefore parent need include child, needs include parent.
what's best way work around this?
you'll have use forward declaration:
//parent.h class child; //forward declaration class parent { vector<child*> m_children; }; //child.h class parent; //forward declaration class child { parent* m_parent; };
Comments
Post a Comment