title: Overloading << and >> in inherited classes
body: <p>I have class Person (first name, last name, address, age) and overloaded operators &lt;&lt; and >> to use it with filestreams:</p>
  
  <pre><code>ostream&amp; operator&lt;&lt; (ostream&amp; outStream, Person&amp; person)
  {
    ...
  }
  
  istream&amp; operator&gt;&gt; (istream&amp; inStream, Person&amp; person)
  {
    ...
  }
  </code></pre>
  
  <p>It works fine - I can read from and write to file easily, but I have added two classes inherited from Person: Student and Worker.</p>
  
  <p>I wrote overloaded operators for them, very similar to those above:</p>
  
  <pre><code>ostream&amp; operator&lt;&lt; (ostream&amp; outStream, Worker&amp; worker)
  {
   ...
  }
  
  istream&amp; operator&gt;&gt; (istream&amp; inStream, Worker&amp; worker)
  {
   ...
  }
  
  
  ostream&amp; operator&lt;&lt; (ostream&amp; outStream, Student&amp; student)
  {
   ...
  }
  
  istream&amp; operator&gt;&gt; (istream&amp; inStream, Student&amp; student)
  {
   ...
  }
  </code></pre>
  
  <p>Only difference are two more fields in each class. The problem is, that when I use overloaded operators with either Student or Worker it seems my compiler uses operators for person. Probably it makes hidden conversion from Student or Worker to Person, but as a result there are no those additional fields written to the file.
  offstream &lt;&lt; People works just the same as offstream &lt;&lt; Students or offstrem Workers.
  Maybe placing overloaded operators declarations for inherited classes first, and for Person later in the code would solve the issue, but i don't find it an elegant solution.</p>
  
  <p>If you have some ideas how to manage with the problem above, I would appreciate.</p>