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> ...
表达式 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()))看起来可能拥有相同效果,但它们全都很可能导致未定义行为,试图二次删除同一对象!
Base& operator=(const Base&) = default; //Move Base(Base&&) = default; Base& operator=(Base&&) = default; }; struct DerivedShared : public Base { public: DerivedShared() //: data(std::shared_ptr<int[]>(new int[3]{1,2,3})) { //data = std::make_shared<int[]>(new int[3...
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> ...