如何重置共享_ptr
How to reset a 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
我在做什么错?
您正在滥用allocate_shared
,这不是您的想法。
您需要的是make_shared
,如下:
BufLbl = std::make_shared<Label>();
相关文章:
- 为共享 ptr 向量实现复制 c'tor?
- C++:在不中断共享的情况下通过引用传递共享 PTR?
- 如何控制共享 ptr 引用计数?
- 这是MSVC 2013中具有共享PTR的单例的正确实现吗?
- 如何从原始 ptr 递增共享 ptr 的计数
- 使用 void 指针:void **ptr.. 如何修改共享内存的值?
- 唯一/共享 ptr 用于在数组超出范围后自动删除阵列
- 如何从集合中删除共享的 PTR 元素
- C 在多个引用上共享PTR发布
- 共享PTR地图与LLDB漂亮的打印机
- 使针对特定托管对象的所有共享 ptr 失效
- c++在没有虚拟析构函数的多态性中共享ptr
- 我如何在void*和boost共享ptr之间切换
- gcc共享ptr副本分配实现
- C++11共享Ptr,共享相同的参考计数器
- 为什么这个显式析构函数会导致共享ptr中的内存损坏
- 在联合中共享ptr
- 从数组的共享ptr访问共享ptr
- 添加对共享ptr的引用会增加引用计数吗?
- 如何在不使代码庞大的情况下处理共享/弱ptr ?