title: Inherited print on screen in subclasses: ostream flow from the parent class
body: <p>My apologies for the bad title, I'm self-taught c++ newbie.</p>
  
  <p>I'd coding the usual example of a Company class along with Employess class and Person class.</p>
  
  <p>Basically my code should create a company, add employees to that and print the full list of employees.</p>
  
  <p>Here's a short version of what I did. It looks quite long, but the isse is just in a couple of lines. All the others are fine, but I needed them so to make the code work.</p>
  
  <pre><code>// g++ test.cpp  -o exe.x &amp;&amp; ./exe.x
  
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  
  class Person {
      private:
          std::string name;
          std::string surname;
  
      public:
          Person() {};
          Person(const std::string n, const std::string m) : name(n), surname(m) {}
          ~Person() {};
  
      friend std::ostream &amp; operator&lt;&lt;(std::ostream &amp; os, const Person &amp; person) {
          return os &lt;&lt; person.name &lt;&lt; " " &lt;&lt; person.surname;
      }
  };
  
  class Employee: public Person {
      private:
          size_t salary;
  
      public:
          Employee(const Person p, const size_t w) {
              salary = w;
          }
          ~Employee() {};
  
      friend std::ostream &amp; operator&lt;&lt;(std::ostream &amp; os, const Employee &amp; employee) {
          std::cout &lt;&lt; employee;                                                  // this should call std::cout from Person
          return os &lt;&lt; ", " &lt;&lt; employee.salary;                                   // this should also print the salary as additional info
      }
  };
  
  class Company {
  
      private:
          std::string companyName;
          size_t maxNumberEmployees;
          std::vector&lt;Employee&gt; employees;
  
      public:
          Company(const std::string n, const size_t p) {
              companyName = n;
              maxNumberEmployees = p;
          }
  
          ~Company() {
              employees.clear();
          }
  
          void addEmployee(const Employee employee) {
              if (employees.size() &lt; maxNumberEmployees) {
                  employees.push_back(employee);
              }
              return;
          }
  
          void listEmployees() const {
              for (Employee employee : employees) {
                  std::cout &lt;&lt; employee &lt;&lt; std::endl;
              }
              return;
          }
  };
  
  
  int main ( int argc, char* argv[] ) {
  
      Company com("CompanyName", 15);
  
      Person per("Name1", "Surname1");
      Employee imp(per, 2000);
      com.addEmployee(imp);
  
      com.listEmployees();
  
      return 0;
  }
  </code></pre>
  
  <p><code>Employee</code> is a sub-class of <code>Person</code>. In the latter, I defined how the <code>std::cout</code> command should print an object of type <code>Person</code>.</p>
  
  <p>When I give <code>std::cout</code> for an <code>Employee</code> object, I want my code to call the <code>std::cout</code> of the <code>Person</code> class, with an additional info defined in the <code>Employee</code> class.</p>
  
  <p>I put two comments in the lines in which I have these troubles. The code gets stuck if I run it this way. There's definetely something wrong in that <code>std::cout &lt;&lt; employee</code>, like if it were a recursive function. But I don't know how to fix that in the way I want it.</p>