3 回答
TA贡献1772条经验 获得超6个赞
shared_ptr
unique_ptr
delete
class A;A* a = ...;delete a;
~A()
auto_ptr<A>
shared_ptr
unique_ptr
不再有未定义的行为:
class A{ class impl; std::unique_ptr<impl> ptr_; // ok!public: A(); ~A(); // ...};
shared_ptr
unique_ptr
shared_ptr
unique_ptr
Complete type requirements for unique_ptr and shared_ptr
unique_ptr shared_ptr
+------------------------+---------------+---------------+
| P() | I | I |
| default constructor | | |
+------------------------+---------------+---------------+
| P(const P&) | N/A | I |
| copy constructor | | |
+------------------------+---------------+---------------+
| P(P&&) | I | I |
| move constructor | | |
+------------------------+---------------+---------------+
| ~P() | C | I |
| destructor | | |
+------------------------+---------------+---------------+
| P(A*) | I | C |
+------------------------+---------------+---------------+
| operator=(const P&) | N/A | I |
| copy assignment | | |
+------------------------+---------------+---------------+
| operator=(P&&) | C | I |
| move assignment | | |
+------------------------+---------------+---------------+
| reset() | C | I |
+------------------------+---------------+---------------+
| reset(A*) | C | C |
+------------------------+---------------+---------------+
unique_ptr
shared_ptr
.
unique_ptr<A>{A*}
A
~unique_ptr<A>()
unique_ptr
A
- 3 回答
- 0 关注
- 979 浏览
添加回答
举报