title: Invalid covariant return type
body: <p>Here is some representative code that gets the error I'm experiencing:</p>
  
  <pre><code>class Data
  {
  };
  
  class Table
  {
    virtual std::vector&lt;Data*&gt; getData() = 0;
    virtual void putData(Data* dataItem) = 0;
    virtual Data* getData(int index) = 0;
  };
  
  class DerivedData : Data
  {
  };
  
  class DerivedTable : Table
  {
    std::vector&lt;DerivedData*&gt; getData() { return myData; } // invalid covariant return type
    void putData(DerivedData *dataItem) { myData.push_back(dataItem); }
    virtual DerivedData* getData(int index) { return myData[index]; } // invalid covariant return type
  
    std::vector&lt;DerivedData*&gt; myData;
  };
  </code></pre>
  
  <p>Firstly, I don't quite understand why it is that the override of putData is happy with the parameters being changed, but I can't change the return type for getData, although I appreciate this is something I can gain an understanding of from more reading.</p>
  
  <p>Secondly, and my main question, how could this code be changed to make it work. My basic goal is to allow for multiple "table" like objects which will store and control data objects. While each data object will share some things in common, there will be some distinct differences which the table will control and work with. For example, one table might have data objects which have a name parameter, and so the table will provide a function which prints a list of all the names of the data it holds. This way I can have generic code which works with all of these table objects, and specialized code which operates only with one type of table.</p>