title: C++ - How to check (at run-time) if Template Function Type matches Function Parameter
body: <pre><code>template &lt;class T&gt; 
  class Links {
  private:
    std::vector&lt;Base*&gt; linkVec;
  
  public:
    Links&lt;T&gt;&amp; operator += (Base*);
  };
  
  template &lt;class T&gt;
  Links&lt;T&gt;&amp; Links&lt;T&gt;::operator+=(Base* b) {
  
    //base is abstract, b will be passed in as derived type of b
    //I want to ONLY add base pointers to the SAME derived type to linkVec
    //How can I check at run-time (using down cast or dynamic cast?) if the 
    //derived type being passed is the same as the other derived types in the linkVec?
    //I would like to throw an exception if a different derived type is attempted to be added 
    //to linkVec
  
    linkVec.push_back(b);
  
    return *this;
  }
  </code></pre>
  
  <p>The comments should sum up what I am trying to do here pretty well. But in short, I have a template class with a vector holding only pointers of the same derived type. I would like to throw an exception if a pointer of different derived type is added. I am not sure how to check the type at run-time and would appreciate any insight.</p>