title: Passing inherited class type as argument
body: <p>I have got problem with passing inherited class type as argument to method that takes its base class type.</p>
  
  <pre><code>class Base {...}
  class Derived : public Base {...}
  class Container {
      vector&lt;Base*&gt; cont; //1
   public:
      void addToCont(Base x) { //2
          cont.push_back(&amp;x);
      }
  }
  
  int main() {
     Container c;
     c.addToCont(Derived(p1,p2)); //3
  }
  </code></pre>
  
  <p>1) I suppose I need to have container of pointers to objects to keep it working</p>
  
  <p>2) Here is error in conversion from Derived to Base</p>
  
  <p>3) I am not supposed to change this call. I tried</p>
  
  <pre><code>Derived d(p1,p2);
  c.addToCont(d);
  </code></pre>
  
  <p>with</p>
  
  <pre><code>addToCont(Base&amp; x)
  </code></pre>
  
  <p>and it worked for me.</p>
  
  <p>My problem is that I've got 3 derived classes and I don't want to overload the add method 3 times. I guess I will have to add some virtual method or some type-casting to those classes, but I couldn't find anything about that. I am novice in inheritance and quite confused of this. Thanks for all your help.</p>