title: up-casting std::shared_ptr using std::dynamic_pointer_cast
body: <p>I'm starting to work with smart pointers in C++0X/11 and I've run into a peculiar situation.
  I want to up cast an instance of an object using shared_ptr.</p>
  
  <p>Class Extend inherits from class Base, where Base class has a virtual destructor in order to make it polymorphic (otherwise dynamic_pointer_cast complains about non-polymorphic class casting).</p>
  
  <p>if therefore:</p>
  
  <pre><code>std::shared_ptr&lt;Base&gt; obj = std::make_shared&lt;Base&gt;();
  </code></pre>
  
  <p>and then I do:</p>
  
  <pre><code>obj = std::dynamic_pointer_cast&lt;Extend&gt;(obj);
  </code></pre>
  
  <ol>
  <li>Is it safe ?</li>
  <li>What happens to other pointers to the object ? Is only obj treating it as Extend, while other shared pointers will still treat it as Base?</li>
  <li>Is it safe to up-cast same instance or should I do something else ?</li>
  </ol>
  
  <p>EDIT: Thank you for the answers. The real reason I was asking this question was to handle XML documents usign a SAX parser, but I got carried away with up/down casting.
  What I sort of wanted was:</p>
  
  <pre><code>std::shared_ptr&lt;Extend&gt; ex = std::dynamic_pointer_cast&lt;Extend&gt;(obj);
  obj = ex;
  </code></pre>
  
  <p>But it makes no sense at all, instead I'll just use an object factory.</p>