3、std::const_pointer_cast() template< class T, class U > std::shared_ptr<T> const_pointer_cast( const std::shared_ptr<U>& r ) noexcept { auto p = const_cast<typename std::shared_ptr<T>::element_type*>(r.get()); return std::shared_ptr<T>(r, p); } 4、std::reinterpret...
// static_pointer_cast example #include <iostream> #include <memory> struct A { static const char* static_type; const char* dynamic_type; A() { std::cout << "construct A " << std::endl; dynamic_type = static_type; } }; struct B: A { static const char* static_type; B() {...
template<class T, class U> std::shared_ptr<T> static_pointer_cast(const std::shared_ptr<U>& sp) noexcept; T:目标类型,即你希望将智能指针转换为的类型。 U:源类型,即智能指针当前所指向的类型。 sp:要转换的智能指针对象。3...
表达式std::shared_ptr<T>(static_cast<T*>(r.get()))、std::shared_ptr<T>(dynamic_cast<T*>(r.get()))及std::shared_ptr<T>(const_cast<T*>(r.get()))看起来可能拥有相同效果,但它们全都很可能导致未定义行为,试图二次删除同一对象!
template <class Ty, class Other> shared_ptr<Ty> static_pointer_cast(const shared_ptr<Other>& sp); ParametersTy The type controlled by the returned shared pointer. Other The type controlled by the argument shared pointer. Other The argument shared pointer.Remarks...
很简单,这是一个函数。shared_ptr<T>是返回值 函数名称:static_pointer_cast;参数const shared_ptr<U>&r'就这么简单。补充:那不叫取址。。那叫引用。你难道这点c++基础都没有?那你还敢看Boost源码?
@@ -266,7 +266,7 @@ bool HttpSession::checkLiveStreamFMP4(const function<void()> &cb){ //直播牺牲延时提升发送性能 setSocketFlags(); onWrite(std::make_shared<BufferString>(fmp4_src->getInitSegment()), true); weak_ptr<HttpSession> weak_self = dynamic_pointer_cast<HttpSession>(shared...
std::shared_ptr<T> static_pointer_cast( const std::shared_ptr<U>& r ) noexcept; (1) (C++11 起) template< class T, class U >std::shared_ptr<T> static_pointer_cast( std::shared_ptr<U>&& r ) noexcept; (2) (C++20 起) template< class T, class U >std::shared_ptr<T> ...
因此,首先将weak_ptr<something>转换为weak_ptr<void>,然后将其转换为void*,然后可以将void*转换回...
std::shared_ptr<T>static_pointer_cast(conststd::shared_ptr<U>&r)noexcept; (1)(since C++11) template<classT,classU> std::shared_ptr<T>static_pointer_cast(std::shared_ptr<U>&&r)noexcept; (2)(since C++20) template<classT,classU> ...