title: Smart pointers and polymorphism
body: <p>I implemented reference counting pointers (called <code>SP</code> in the example) and I'm having problems with polymorphism which I think I shouldn't have.</p>
  
  <p>In the following code:</p>
  
  <pre><code>    SP&lt;BaseClass&gt; foo()
      {   
          // Some logic...
          SP&lt;DerivedClass&gt; retPtr = new DerivedClass();
          return retPtr;
      }
  </code></pre>
  
  <p><code>DerivedClass</code> inherits from <code>BaseClass</code>.  With normal pointers this should have worked, but with the smart pointers it says <code>"cannot convert from 'SP&lt;T&gt;' to 'const SP&lt;T&gt;&amp;"</code> and I think it refers to the copy constructor of the smart pointer.</p>
  
  <p>How do I allow this kind of polymorphism with reference counting pointer? 
  I'd appreciate code samples cause obviously im doing something wrong here if I'm having this problem.   </p>
  
  <p><strong>PS:</strong> Please don't tell me to use standard library with smart pointers because that's impossible at this moment.</p>