title: Polymorphism with pointers/boost::shared_ptr
body: <p>Consider the following example of polymorphism in C++. To me, this is unexpected behavior, which probably lies in the fact that I am still thinking too much in Java. The question to me is now: How do I get the pointer example to call the more specific method.</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string.h&gt;
  #include &lt;boost/tr1/memory.hpp&gt;
  
  class Image {
   public:
    Image(std::string className = &quot;Image&quot;) 
        : className_(className)
      {}
  
    virtual ~Image() {}
  
    virtual std::string className() {
      return className_;
    }
  
   private:
    std::string className_;
  };
  
  class RightImage : public Image {
   public:
    RightImage()
        : Image(&quot;RightImage&quot;)
      {}
  };
  
  class Processor{
   public:
    void process(Image&amp; image){
      std::cout &lt;&lt; &quot;Invoking process(Image&amp; image) with image of type \&quot;&quot; &lt;&lt; image.className() &lt;&lt; &quot;\&quot;&quot; &lt;&lt; std::endl;
    }
    void process(RightImage&amp; rightImage){
      std::cout &lt;&lt; &quot;Invoking process(RightImage&amp; rightImage) with rightImage of type \&quot;&quot; &lt;&lt; rightImage.className()  &lt;&lt; &quot;\&quot;&quot; &lt;&lt; std::endl;
    }
  
    void process(Image* image){
      std::cout &lt;&lt; &quot;Invoking process(Image* image) with image of type \&quot;&quot; &lt;&lt; image-&gt;className() &lt;&lt; &quot;\&quot;&quot; &lt;&lt; std::endl;
    }
    void process(RightImage* rightImage){
      std::cout &lt;&lt; &quot;Invoking process(RightImage* rightImage) with rightImage of type \&quot;&quot; &lt;&lt; rightImage-&gt;className()  &lt;&lt; &quot;\&quot;&quot; &lt;&lt; std::endl;
    }
  };
  
  int main(int argc, char **argv) {
        std::tr1::shared_ptr&lt;Image&gt; rightImageSharedPtr(new RightImage());
        Image* rightImagePointer = new RightImage();
        RightImage rightImage;
        Processor processor;
        std::cout &lt;&lt; &quot;value:                   &quot;;
        processor.process(rightImage);
        std::cout &lt;&lt; &quot;shared_ptr:              &quot;;
        processor.process(*rightImageSharedPtr);
        std::cout &lt;&lt; &quot;old fashioned pointer 1: &quot;;
        processor.process(*rightImagePointer);
        std::cout &lt;&lt; &quot;old fashioned pointer 2: &quot;;
        processor.process(rightImagePointer);
  }
  </code></pre>
  <p>The output of that program is:</p>
  <blockquote>
  <p>value:                   Invoking process(RightImage&amp; rightImage) with rightImage of type &quot;RightImage&quot;</p>
  <p>shared_ptr:              Invoking process(Image&amp; image) with image of type &quot;RightImage&quot;</p>
  <p>old fashioned pointer 1: Invoking process(Image&amp; image) with image of type &quot;RightImage&quot;</p>
  <p>old fashioned pointer 2: Invoking process(Image* image) with image of type &quot;RightImage&quot;</p>
  </blockquote>
  <p>How can I make the last three examples also call <code>process(RightImage&amp;)</code> and <code>process(RightImage*)</code>?</p>