Boost logo

Boost Users :

From: Zumichu (zumichu_at_[hidden])
Date: 2003-06-08 23:02:06


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?


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net