Open wsxk opened 7 months ago
https://wsxk.github.io/c++smart_pointer_copy/
智能指针
unique_ptr shared_ptr weak_ptr
拷贝构造函数 ->重载 std::vector std::vector优化 template std::array array 和 vector的区别
智能指针 c++中,我们可以使用new delete关键字来从heap上分配内存。 然而,有时候我们会忘记delete,所以有了智能指针。 智能指针有三类unique_ptr,shared_ptr,weak_ptr
unique_ptr 在当前作用域创建的unique_ptr,在作用域结束时会自动销毁分配内存。 shared_ptr 所有指向同一个对象的 shared_ptr指针,只有在所有的 shared_ptr离开作用域后,才会自动销毁 weak_ptr 同shared_ptr,但是不会增加计数器的技术,当所有shared_ptr离开作用域后,即使weak_pointer仍然存在,也会自动销毁指向对象。
class Entity { public: Entity() { std::cout <<
https://wsxk.github.io/c++smart_pointer_copy/
智能指针
拷贝构造函数 ->重载 std::vector std::vector优化 template std::array array 和 vector的区别
智能指针 c++中,我们可以使用new delete关键字来从heap上分配内存。 然而,有时候我们会忘记delete,所以有了智能指针。 智能指针有三类unique_ptr,shared_ptr,weak_ptr
unique_ptr 在当前作用域创建的unique_ptr,在作用域结束时会自动销毁分配内存。 shared_ptr 所有指向同一个对象的 shared_ptr指针,只有在所有的 shared_ptr离开作用域后,才会自动销毁 weak_ptr 同shared_ptr,但是不会增加计数器的技术,当所有shared_ptr离开作用域后,即使weak_pointer仍然存在,也会自动销毁指向对象。
include
class Entity { public: Entity() { std::cout <<