title: Function Overloading with Shared Pointers
body: <p>I had expected this to work but during compiling I get an error, if anyone can point out my mistake or how I should resolve it would be much appreciated. Preferably without resorting to casts. Is there a standard design pattern to do this?</p>
  
  <p>I made a simplified example of my code that shows the problem and my intentions. I have a (normally abstract) base class (shape) with derived classes (Square, Circle). I have shared_ptr references to the objects and want to execute the according functions in a different calls based on the shared_ptr type.</p>
  
  <p>Below is the code that is not working and short of doing dynamic type casting and an ugly if statement I do not know how to correct it. </p>
  
  <pre><code>//Standard includes
  #include "memory"
  #include &lt;typeinfo&gt;
  
  class Shape
  {
  public:
      virtual ~Shape() = default;
  };
  class Circle : public Shape { };
  class Square : public Shape { };
  
  class Logging
  {
      static void print(std::shared_ptr&lt;Circle&gt; shape)
      {
          std::cout &lt;&lt; "This object is a " &lt;&lt; typeid(*shape).name() &lt;&lt; std::endl;
      }
  
      static void print(std::shared_ptr&lt;Square&gt; shape)
      {
          std::cout &lt;&lt; "This object is a " &lt;&lt; typeid(*shape).name() &lt;&lt; std::endl;
      }
  };
  
  int main() {
      //Shared Pointer Shape Declaration
      std::shared_ptr&lt;Shape&gt; circle = std::make_shared&lt;Circle&gt;();
      std::shared_ptr&lt;Shape&gt; square = std::make_shared&lt;Square&gt;();
  
      //Printing Shapes
      Logging::print(circle);     //Compiler ERROR: none of the 2 overloads could convert all the argument types
      Logging::print(square);     //Compiler ERROR: none of the 2 overloads could convert all the argument types
  
  return 0;
  }
  </code></pre>
  
  <p>Thanks in advance for any helpful answers.</p>