title: Casting std::vector<std::string> to void*
body: <p>I'm trying to pass in a <code>std::vector&lt;std::string&gt;</code> to a <code>void*</code> for use in a callback function which requires a <code>void*</code> to be passed to it. The callback is a <code>sqlite_exec</code> callback. However, I am getting a segfault when casting <code>vec</code> to a <code>void*</code>. So how can I pass in a <code>std::vector&lt;std::string&gt;</code> into such a callback?</p>
  
  <pre><code>static int cb_vector(void* vec, int argc, char**argv, char**colNm){
      std::vector&lt;std::string&gt;* myvec = (std::vector&lt;std::string&gt;*)vec;
      for(int i = 0; i &lt; argc; i++){
          myvec-&gt;push_back(argv[i]);
      }
      return 0;
  }
  
  std::vector&lt;std::string&gt; myfunc(){
      std::vector&lt;std::string&gt; vec;
      int rc = sqlite3_exec(_db, SQL, cb_vector, (void*)&amp;vec, NULL);
      return vec;
  }
  </code></pre>
  
  <p>I have already looked the following resources, but they did not answer my quesion.</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/725040/converting-void-to-stdvectorunsigned-char">Converting (void*) to std::vector&lt;unsigned char&gt;</a></li>
  <li><a href="https://stackoverflow.com/questions/14825274/passing-a-vector-to-a-function-as-void-pointer">Passing a vector to a function as void pointer</a></li>
  </ul>