title: Generalized copy constructors
body: <p>Why do classes like <code>shared_ptr</code> have another template in their constructors?</p>
  
  <p>For example:</p>
  
  <pre><code>template&lt;class T&gt; class shared_ptr {
  public:
    template&lt;class Y&gt;
    explicit shared_ptr(Y * p);
  </code></pre>
  
  <p>I've been reading Scott Meyers's <em>Effective C++</em>, item 45, which says the idea behind it is to make polymorphism possible through them; that is, construct <code>shared_ptr&lt;A&gt;</code> from <code>shared_ptr&lt;B&gt;</code> if B is derived from A.</p>
  
  <p>But isn't defining a constructor like</p>
  
  <pre><code>explicit shared_ptr(T * p);
  </code></pre>
  
  <p>enough? I mean, this code works just fine:</p>
  
  <pre><code>class C1 {
  };
  
  class C2 : public C1 {
  };
  
  template&lt;typename T&gt;
  class A
  {
  public:
    A(T &amp;a)
    {
      var1 = a;
    }
  
    T var1;
  };
  
  int main(int argc, char *argv[])
  {
    C2 c2;
    A&lt;C1&gt; inst1(c2);
  }
  </code></pre>
  
  <p>So why do we need another template for constructor there?</p>