c++ - static_cast with boost::shared_ptr?

c++ - static_cast with boost::shared_ptr?

What is the equivalent of a static_cast with boost::shared_ptr? In other words, how do I have to rewrite the following Base* b=new Derived(); Derived* d=static_cast<Derived*>(b); when using shar…


Difference in behavior while using dynamic_cast with reference and pointers

I was checking the behavior of dynamic_cast and found that when it fails, std::bad_cast exception is thrown only if the destination is a reference type. If the destination is a pointer type then no e…


c++ - Downcasting shared_ptr<Base> to shared_ptr<Derived>?

Update: the shared_ptr in this example is like the one in Boost, but it doesn't support shared_polymorphic_downcast(or dynamic_pointer_cast or static_pointer_cast for that matter)! I'm trying to init…


c++11 - static_pointer_cast for weak_ptr

In c++0x, there is a std::static_pointer_cast for std::shared_ptr, but there is no equivalent method for std::weak_ptr. Is this intentional, or an oversight? If an oversight, how would I define an app…


c++ - Downcasting shared pointer to derived class with additional functionality-is this safe?

Consider the following outline: class Base{/*...*/}; class Derived:public Base{public: void AdditionalFunctionality(int i){/*...*/}}; typedef std::shared_ptr<Base> pBase; typedef s…


c++ - How does one downcast a std::shared_ptr?

Consider: struct SomethingThatsABase{virtual bool IsChildOne() const{return false;}virtual bool IsChildTwo() const{return false;}}; struct ChildOne:public SomethingThatsABase{…


c++ - Passing shared_ptr<Derived> as shared_ptr<Base>

What is the best method to go about passing a shared_ptr of a derived type to a function that takes a shared_ptr of a base type? I generally pass shared_ptrs by reference to avoid a needless copy: int…



c++ - “Downcasting” unique_ptr<Base> to unique_ptr<Derived>

I have a series of factories that return unique_ptr<Base>. Under the hood, though, they are providing pointers to various derived types, i.e unique_ptr<Derived>, unique_ptr<DerivedA>, unique_ptr<Deriv…


Alternatives of static_pointer_cast for unique_ptr

I understand that using static_pointer_cast with unique_ptr would lead to a shared ownership of the contained data. In other terms, what I'd like to do is: unique_ptr<Base> foo=fooFactory();// do…




dynamic_pointer_cast shared_ptr std upcast unique_ptr pointer class base cast boost