C++:智能指针 [unique_ptr]

0x1 基本使用

0x11 get() [ 参照auto_ptr ]

0x12 release() [ 参照auto_ptr ]

0x13 reset() [ 参照auto_ptr ]

0x14 get_deleter() [ 新增 ]

0x15 operator bool [ 新增 ]

可以通过nullptr判断,auto_ptr部支持

unique_ptr<string> p1(new string("HelloWorld"));

p1.release();
if (p1 == nullptr) {
   
    cout << "p1 is nullptr" << endl;
}

0x16 swap() [ 新增 ]

unique_ptr<string> p1(new string("HelloWorld"));
unique_ptr<string> p2(new string("VsCode"));

cout << *p1 << endl;
cout << *p2 << endl;
swap(p1, p2);
cout << *p1 << endl;
cout << *p2 << endl;

0x2 make_unique函数 [unique_ptr在C++11引入,make_unique在C++14引入]

make_unique是C++14引入的一个函数模板

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值