view plaincopy to clipboardprint void f()
{
InvestmentPtr pInvestment = new Investment(123);//重载构造函数实现RIIA
ProfitManagerPtr pProfit = new Profit(123);
pInvestment ->DoSomeThing();//这个动作太酷了,它俨然就是一个指针!
...
}
void f()
{
InvestmentPtr pInvestment = new Investment(123);//重载构造函数实现RIIA
ProfitManagerPtr pProfit = new Profit(123);
pInvestment ->DoSomeThing();//这个动作太酷了,它俨然就是一个指针!
...
}
OK智能指针诞生了~ 或许可以给他套上template这顶小帽子,他将呈现出更加的通用的形式。
view plaincopy to clipboardprint void f()
{
MySmartPtr
MySmartPtr
pInvestment ->DoSomeThing();//这个动作太酷了,它俨然就是一个指针!
...
}
void f()
{
MySmartPtr
MySmartPtr
pInvestment ->DoSomeThing();//这个动作太酷了,它俨然就是一个指针!
...
}
你可能会询问智能指针的更多细节,但让我们就此打住一下。让我们先看看引用计数以及如何用智能指针简化COM开发的问题。
作者“liuchang5的专栏”