title: Generic output operator overloading with inheritance
body: <p>Given an abstract base class <code>Object</code> and 2 derived classes, <code>Person</code> and <code>Gathering</code>. Where <code>Gathering</code> is a data structure which stores pointers to <code>Person</code> or other <code>Gathering</code> pointers inside of an array.</p>
  
  <p>I would like to override the output operator so it prints any type of <code>Object</code>. But I do not know how to override the operator properly so when it receives type <code>Object</code> it knows how to deal with it.</p>
  
  <p>Here is a simple code that exemplifies what I'm trying to achieve:</p>
  
  <pre><code>#import &lt;iostream&gt;
  #import &lt;cstring&gt;
  
  class Object {
  public:
      virtual ~Object(){};
  };
  
  class Person : public Object {
  private:
      char * m_name;
  public:
      Person(char * input) {
          m_name = new char[strlen(input)];
          strncpy(m_name, input, strlen(input));
      }
  
      char* getName() const{
          return m_name;
      }
  
      friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const Person* p) {
          os &lt;&lt; p-&gt;getName();
          return os;
      }
  };
  
  class Gathering : public Object {
  private:
      int m_size;
      Object* m_buffer;
  
  public:
      Gathering() : m_size(10) 
      {}
  
      friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const Gathering* v) {
          for (int i=0; i&lt;v-&gt;getSize(); i++) {
              //Trying to send Object to outputstream..
              os &lt;&lt; "[" &lt;&lt; v-&gt;getBuffer()[i] &lt;&lt; "]";
          }
      }
  
      int getSize() const {
          return m_size;
      }
  
      Object* getBuffer() const {
          return m_buffer;
      }
  };
  </code></pre>
  
  <p>I am very aware of what the problem is, how do Ideal with this? Any references or pointers are very appreciated.</p>