温馨提示×

C++11及以后版本中std::shared_ptr的新特性有哪些

c++
小樊
81
2024-08-18 01:54:36
栏目: 编程语言

  1. std::make_shared()函数:C++11中引入了std::make_shared()函数,可用于创建shared_ptr对象,减少了动态内存分配的开销。

  2. std::allocate_shared()函数:C++11中引入了std::allocate_shared()函数,允许在已经分配的内存块上创建shared_ptr对象,提高了性能。

  3. std::shared_ptr::get_deleter()函数:C++11中引入了std::shared_ptr::get_deleter()函数,用于获取与shared_ptr对象关联的删除器。

  4. std::shared_ptr::owner_before()函数:C++11中引入了std::shared_ptr::owner_before()函数,用于比较两个shared_ptr对象的所有权关系。

  5. std::shared_ptr::make_shared_enabler:C++17中引入了std::shared_ptr::make_shared_enabler,用于解决循环依赖的问题。

  6. std::shared_ptr::shared_from_this()函数:C++17中引入了std::shared_ptr::shared_from_this()函数,用于在成员函数中获取this指针对应的shared_ptr对象。

  7. std::shared_ptr::weak_from_this()函数:C++17中引入了std::shared_ptr::weak_from_this()函数,用于在成员函数中获取this指针对应的weak_ptr对象。

0