title: How to add element to various container depending of type using template
body: <p>I've got rather silly question but I hope that you can help me with that. </p>
  
  <p>I've got class with multiple vectors, and this vectors have different storage types. </p>
  
  <pre><code>class BaseClass{
    std::string Name;
  }
  
  class B : public BaseClass{
  
  }
  class C : public BaseClass{
  
  }
  
  class A{
    vector&lt;std::pair&lt;std::string, B&gt;&gt; V1;
    vector&lt;std::pair&lt;std::string, C&gt;&gt; V2;
  }
  </code></pre>
  
  <p>inside my class A there is a template function to add elements to this vectors:</p>
  
  <pre><code>template &lt;class T&gt;  void addElement(T Obj);
  </code></pre>
  
  <p>I want this situation to happen: </p>
  
  <pre><code>A a;
  B b;
  C c;
  
  
  a.addElement&lt;B&gt;(b) -&gt; then element b is added to vector V1
  a.addElement&lt;C&gt;(c) -&gt; then element c is added to vector V2
  </code></pre>
  
  <p>I came up with something like this:</p>
  
  <pre><code>template &lt;class T&gt;  void addElement(T Obj){
    std::pair&lt;std::string, T&gt; AddedPair(Obj.Name, Obj);
  
     if (typeid(T) == typeid(B)) 
      V1.push_back(AddedPair);
  
     if (typeid(T) == typeid(C)) 
      V2.push_back(AddedPair);
  
  }
  </code></pre>
  
  <p>But unfortunetly this code won't compile because somehow template is compiled as a whole and if I use B as a template argument then compiler cannot convert B to C despite that program will never reach a point where this convertions can happened :(</p>
  
  <p>Do you have any suggestions how can I solve this problem? I would be very greatful.</p>