一个带有智能指针的简单树类

时间:2017-03-17 19:11:31

标签: c++ c++11 memory-management smart-pointers

我正在学习智能指针。使用智能指针,我可以想到一个简单的类来实现二叉树,如下所示。

class BinTree
{
  ....
  std::unique_ptr<BinTree> leftChild;
  std::unique_ptr<BinTree> rightChild;
};

事情变得复杂,如果我还想保留指向父节点的指针,因为在这种情况下,每个节点将指向3个节点(2个子节点和一个父节点)。当然可以使用shared_ptr,但我读过它效率太低了。那么,这里最好的解决方案是什么?

我正在考虑使用weak_ptr指向父母,因为孩子无论如何也不会创建/拥有父母,但是weak_ptr无法创建unique_ptr,只有shared_ptr sp_report CustomSummary show Label, Amount parameters DateFrom = {d'2017-01-01'}, DateTo={d'2017-12-31'}, AccountFilterType= 'OrdinaryIncome', SummarizeRowsBy = 'Customer', SummarizeColumnsBy = 'Month' where RowType='DataRow'

0 个答案:

没有答案