title: Passing inherited class to function that takes base class
body: <p>I created a simple example to demonstrate a problem I am having with my database manager. It has the basic objects of Table, Row, and Column. However to clarify objects and schemas, those classes are extended such as MyTable, MyRow, ColumnName, etc. The generic functions to grab data from the database itself, however, always takes those base classes, specifically Row and Column.</p>
  <p>I am having trouble designing a way to be able to pass extended classes to those generic data retrieving functions. This maybe could be solved with pointers, but you can get castrated here for practically mentioning them.</p>
  <p>So, how would one properly implement this code, assuming the intentions are clear.</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  class Column {
      public:
          std::string name;
          std::string value;
          Column(std::string name, std::string value)
              :name(name), value(value)
          {
              
          }
  };
  class Row {
      public:
          std::vector&lt;Column&gt; columns;
  };
  class MyRow : public Row {
      
  };
  
  void GetRows(std::vector&lt;Row&gt; &amp;rows){
     Column colA(&quot;ColA&quot;, &quot;ValA&quot;);
     Column colB(&quot;ColB&quot;, &quot;ValB&quot;);
     Row row;
     row.columns.push_back(colA);
     row.columns.push_back(colB);
     rows.push_back(row);
  }
  
  int main()
  {
      // Cool
      std::vector&lt;Row&gt; rows;
      GetRows(rows);
       
      // Not so cool...
      std::vector&lt;MyRow&gt; myrows;
      GetRows(myrows);    
  }
  </code></pre>