[英]How to reset a shared_ptr?
I'm trying to do this (using a custom class, and STL shared_ptr from #include <memory>
):我正在尝试这样做(使用自定义类和来自
#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>
I'm getting this error:我收到此错误:
error C2903: 'rebind' : symbol is neither a class template nor a function template
What am I doing wrong?我究竟做错了什么?
You're abusing allocate_shared
, which isn't what you think.你在滥用
allocate_shared
,这不是你想的。
What you need is make_shared
, like this:你需要的是
make_shared
,像这样:
BufLbl = std::make_shared<Label>();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.