如何重置shared_ptr?

时间:2012-11-13 04:03:31

标签: c++ stl c++11 shared-ptr

我正在尝试这样做(使用自定义类和来自#include <memory>的STL shared_ptr):

shared_ptr<Label> BufLbl;

BufLbl = allocate_shared<Label>(Label());
BufLbl->YCoord = 3;
BufLbl->XCoord = 2; 
BufLbl->Width = 5;
BufLbl->Data = "Day 1";
Screen.Controls.push_back(BufLbl);

BufLbl = allocate_shared<Label>(Label());
BufLbl->YCoord = 4;
BufLbl->XCoord = 6; 
BufLbl->Width = 1;
BufLbl->Data = "2";
Screen.Controls.push_back(BufLbl);

<repeat>

我收到了这个错误:

error C2903: 'rebind' : symbol is neither a class template nor a function template

我做错了什么?

1 个答案:

答案 0 :(得分:2)

你在滥用allocate_shared,这不是你的想法。

您需要的是make_shared,如下所示:

BufLbl = std::make_shared<Label>();