title: c++ pass any child object with parent type to method
body: <p>I'm trying to pass a child object to a method, but do not know the object type ahead of time, other than that it will be inherited from a parent.
  I can set the type as parent, and the compiler is happy, however I loose child data when this process takes place.</p>
  
  <pre><code>class Parent{
  public:
  Parent(int val);
  };
  
  class Child{
  public:
  Child(double childval, int parentval)
  };
  </code></pre>
  
  <hr>
  
  <pre><code>Child::Child(double childval, int parentval) : Parent(parentval)
  
  Child childObj = new Child(cval, pval);
  </code></pre>
  
  <hr>
  
  <pre><code>int someOtherMethod(Parent pobj);
  someOtherMethod(childObj);  // Looses child data but parent data persists. How to keep child data too?
  </code></pre>
  
  <hr>
  
  <p>Is fine, however if I pass childObj into someOtherMethod the child data is lost, and only the parent data is maintained.</p>
  
  <p>I have looked into virtual functions, dynamic binding, "set" but have become totally confused about which direction I should be taking.</p>
  
  <p>Can someone please put me back on track?</p>
  
  <p>Thanks.</p>