Without experience with shared_ptr<> I wonder if the following usage example is suitable, and is it also a good opportunity to return shared_ptr<> user.
I have a diagram that looks like a structure with multiple connections between nodes. During the graph traversal, each node is assigned a value (calculated from connected nodes), and I want the user to easily access the value. All this looks (greatly simplified) as follows:
class Pool; class Node { public: typedef std::tr1::shared_ptr<Node> Ptr; ... void compute_dependencies() { ...
and the user calls:
Pool pool(); Node::Ptr node1 = Pool::create_node(...); Node::Ptr node2 = Pool::create_node(...); .... pool.traverse_and_evaluate();
This has the advantage that the user has direct access to the nodes he cares about (dependencies are often uninteresting). But I'm not 100% sure, this is a good idea.
Thanks for your input!
Edit: There are no circular dependencies.
c ++ shared-ptr
bbtrb
source share