title: How to cast vector<int> to int*
body: <p>I have to maintain a program that nobody has touched since 2004.</p>
  
  <pre><code>class CSolver
  {  
   ...  
   ClauseIdx add_clause (int * lits, int n_lits);
  }
  
  void and2 (CSolver &amp; solver)   
  {  
  vector &lt;int&gt; lits;  
  ...  
  solver.add_clause(lits.begin(), lits.size());  
  }
  </code></pre>
  
  <p>The compiler complains that:</p>
  
  <blockquote>
    <p>error: no matching function for call to ‘CSolver::add_clause(__gnu_cxx::__normal_iterator&lt;int*, std::vector&lt;int, std::allocator&lt;int&gt; &gt; &gt;, size_t)’</p>
  </blockquote>
  
  <p>I try to cast it</p>
  
  <pre><code>solver.add_clause((int*)lits.begin(), lits.size());
  </code></pre>
  
  <p>But there is still a complaint:</p>
  
  <blockquote>
    <p>error: invalid cast from type ‘__gnu_cxx::__normal_iterator&lt;int*, std::vector&lt;int, std::allocator&lt;int&gt; &gt; &gt;’ to type ‘int*’  </p>
  </blockquote>
  
  <p>I want to look for a quick fix on this, because changing interface of CSolver will result
  changing the whole program.</p>
  
  <p>Thanks in advance.</p>