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

   2024-10-01 2840
核心提示:std::make_shared()函数:C++11中引入了std::make_shared()函数,可用于创建shared_ptr对象,减少了动态内存分配的开销。std::al

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

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

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

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

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

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

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

 
举报打赏
 
更多>同类物流大全
推荐图文
推荐物流大全
点击排行

网站首页  |  关于我们  |  联系方式网站留言    |  赣ICP备2021007278号