The expressions std::shared_ptr<T>(static_cast<T*>(r.get())), std::shared_ptr<T>(dynamic_cast<T*>(r.get())) and std::shared_ptr<T>(const_cast<T*>(r.get())) might seem to have the same effect, but they all will likely result in undefined behavior, attempting to delete th...
表达式 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())) 看起来可能拥有相同效果,但它们全都很可能导致未定义行为,试图删除同一对象二次!
表达式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()))看起来可能拥有相同效果,但它们全都很可能导致未定义行为,试图二次删除同一对象!
如果r是空的,新的也是空的shared_ptr%28但其存储的指针不一定为空%29。 否则,新的shared_ptr将与r,但如果dynamic_cast由dynamic_pointer_cast返回空指针。 让Y成typenamestd::shared_ptr<T>::element_type,然后产生的std::shared_ptr%27s存储的指针将通过按%29的顺序调用%28获得:...
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> ...
Let Y be typename std::experimental::shared_ptr<T>::element_type, then the resulting std::experimental::shared_ptr's stored pointer will be obtained by calling (in respective order): 1) static_cast<Y*>(r.get()).2) dynamic_cast<Y*>(r.get()) (if the result of the dynamic_cast ...