9 Jun
2003
9 Jun
'03
4:02 a.m.
Basically I'm having trouble understanding exactly how to use shared_ptr . If I have a class: GraphNode { public: AddChild(shared_ptr<GraphNode> n) { m_Children.push_back(n); shared_ptr<GraphNode> thisptr(this); n->m_Parents.push_back(thisptr); } DeleteChild(shared_ptr<GraphNode> n); private: vector<shared_ptr<GraphNode> > m_Children; vector<shared_ptr<GraphNode> > m_Parents; }; main() { shared_ptr<GraphNode> n1(new GraphNode()); shared_ptr<GraphNode> n2(new GraphNode()); n1->AddChild(n2); } doing it this way gives me a run-time error that seems to have to do with updating the child node's parent vector with the parent node's this pointer. Am I not using the shared_ptr right?