title: What is diffrence between lock() and expired()? weak_ptr C++
body: <p>Recently I started at C++11.
  I studied about <code>weak_ptr</code>. There exist two ways of getting raw pointer.</p>
  
  <ol>
  <li><p><code>lock()</code> function</p>
  
  <pre><code>shared_ptr&lt;Foo&gt; spFoo = wpPtr.lock();
  
  if(spFoo) {
      spFoo-&gt;DoSomething();
  }
  </code></pre></li>
  <li><p><code>expired()</code> function</p>
  
  <pre><code>if(!wpPtr.expired())
  {
      shared_ptr&lt;Foo&gt; spFoo = wpPtr.lock();
      spFoo-&gt;DoSomething();
  }
  </code></pre></li>
  </ol>
  
  <p>Which is the better way? What is different between the two ways?</p>