title: convert std::shard_ptr of derived class to that of base class
body: <pre><code>#include &lt;iostream&gt;
  #include &lt;memory&gt;
  
  class Base{
  };
  class Derive : public Base{
  };
  
  void foo(std::shared_ptr&lt;Base&gt;&amp; p){
  }
  void bar(const std::shared_ptr&lt;Base&gt;&amp; p){
  }
  
  int main(){
  
      auto base = std::make_shared&lt;Base&gt;();
      foo(base);
      bar(base);
  
      auto derive = std::make_shared&lt;Derive&gt;();
      foo(derive);
      bar(derive);
  
      return 0;
  }
  </code></pre>
  
  <blockquote>
    <p>g++ -std=c++0x test.cpp</p>
  </blockquote>
  
  <p>The compiler says:</p>
  
  <pre><code>test.cpp:21:5: error: no matching function for call to 'foo'
      foo(derive);
      ^~~
  test.cpp:9:6: note: candidate function not viable: no known conversion from 'std::__1::shared_ptr&lt;Derive&gt;' to
        'std::shared_ptr&lt;Base&gt; &amp;' for 1st argument
  void foo(std::shared_ptr&lt;Base&gt;&amp; p){
  </code></pre>
  
  <p>Could you explain why you can't pass the shared_ptr of derived class to foo(), while you can pass it to bar() that receives const reference of the shared_ptr.</p>
  
  <p>Sorry for my poor English.
  Thanks.</p>