std::static_pointer_cast, std::dynamic_pointer_cast, std::const_pointer_cast

std::static_pointer_cast, std::dynamic_pointer_cast, std::const_pointer_cast

template< class T, class U >
shared_ptr<T> static_pointer_cast( const shared_ptr<U>& r );
(1)(since C++11)
template< class T, class U >
shared_ptr<T> dynamic_pointer_cast( const shared_ptr<U>& r );
(2)(since C++11)
template< class T, class U >
shared_ptr<T> const_pointer_cast( const shared_ptr<U>& r );
(3)(since C++11)
   

Creates a new instance of std::shared_ptr whose managed object type is obtained from the r's managed object type using a cast expression. Both smart pointers will share the ownership of the managed object.

The resulting std::shared_ptr's managed object will be obtained by calling (in respective order):

1) static_cast<T*>(r.get()).
2) dynamic_cast<T*>(r.get()) (If the result of the dynamic_cast is 0, the returned shared_ptr will be empty).
3) const_cast<T*>(r.get()).

In any case, if the parameter r is an empty std::shared_ptr the result will be a new empty std::shared_ptr.

Parameters

r-The pointer to convert

Exceptions

noexcept specification:  
noexcept
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值