std::shared_ptr 与普通指针的转换

来源:互联网 发布:网页抢购软件 编辑:程序博客网 时间:2024/05/16 15:45

shared_ptr 是一个类,用模板支持很多类型。

1.shared_ptr到普通指针

shared_ptr<int>shared_a(10);

int *b=NULL;

b = &*shared_a;//*share_a 拷贝shared_a里面值创建临时对象, 再&取得临时对象地址

b = shared_a.get();


2.普通指针到shared_ptr

std::shared_ptr<CMyselfVideoWnd> myselfVideoWnd;

myselfVideoWnd.reset( new CMyselfVideoWnd());

在duilib 窗口delete在OnFinalMessage():

__super::OnFinalMessage(hWnd);
delete this;