title: Disappearing contents of std::vector<std::string>
body: <p>I have a vector of strings which are changing its contents for no apparent reason. Can't really explain what is going on. Sorry for a long listing, but it's really bugging me.</p>
  
  <p>I have a GUI application which loads some files and uses a reader object which state can be set by using a <code>parse(int argc, char* argv[])</code> method. The arguments are set in a dialog by checking various boxes and entering values. Here is a struct I use to hold the data from the dialog:</p>
  
  <pre><code>struct PointFilter
  {
      PointFilter(): argc(0) {};
      ~PointFilter() {};
      int argc;
      std::vector&lt;std::string&gt; args;
  };
  </code></pre>
  
  <p>This struct is a member of the dialog class and after pressing ok button its populated with appropriate values. The values are taken from text boxes on the dialog into a stringstream and then pushed back into a std::vector:</p>
  
  <pre><code>class AdvancedLoadDialog
  {
  public:
      AdvancedLoadDialog(const Glib::RefPtr&lt;Gtk::Builder&gt;&amp;);
      ~AdvancedLoadDialog();
  
      PointFilter get_point_filter()
      {
          return this-&gt;point_filter;
      }
  
  private:
      PointFilter point_filter;
      void on_ok_btn_clicked();
  
  void AdvancedLoadDialog::on_ok_btn_clicked()
  {
      std::stringstream filter_stream;
          // filter_stream &lt;&lt; some_values_from_textboxes ...
  
      std::vector&lt;std::string&gt; args;
      std::string arg;
  
      // we need a dummy first argument to emulate the command line
      args.push_back("filter");
  
      while (filter_stream &gt;&gt; arg)
      {
          args.push_back(arg);
      }       
  
      point_filter.argc = args.size() &gt; 1 ? args.size() : 0;
      point_filter.args = args;
  
      advanced_load_dialog-&gt;hide_all();
  }
  </code></pre>
  
  <p>Everything works fine till this point and we have an <code>AdvancedLoadDialog</code> object with <code>point_filter</code> member which holds our arguments. Now in a separate window I take the point_filter object and pass it to a constructor of <code>LoadWorker</code> class, which loads the files and also has a <code>PointFilter</code> member.</p>
  
  <pre><code>load_worker = new LoadWorker(..., advanced_load_dialog-&gt;get_point_filter())
  </code></pre>
  
  <p>And then:</p>
  
  <pre><code>LoadWorker::LoadWorker(..., PointFilter pf) :
      point_filter    (pf)
  </code></pre>
  
  <p>All well and good. Now in the <code>LoadWorker::run()</code> function I take the arguments from the point_filter, convert them into std::vector and pass them them to the `parse(int argc, char* argv[]) function I need.</p>
  
  <pre><code>void LoadWorker::run()
  {
      std::cout &lt;&lt; "LoadWorker::file_filter contents: \n"
              &lt;&lt; "point_filter.argc: " &lt;&lt; point_filter.argc &lt;&lt; "\n"
              &lt;&lt; "point_filter.args: " &lt;&lt; std::endl;
      for (int i = 0; i &lt; point_filter.argc; ++i)
          std::cout &lt;&lt; point_filter.args[i] &lt;&lt; std::endl;
  
          // ...
  
      if (point_filter.argc != 0)
      {
          std::cout &lt;&lt; "Using filter: " &lt;&lt; std::endl;
  
          std::vector&lt;char*&gt; argv;
  
          for (std::vector&lt;std::string&gt;::const_iterator it = point_filter.args.begin();
                  it != point_filter.args.end(); ++it)
          {
              argv.push_back(const_cast&lt;char*&gt;(it-&gt;c_str()));
          }
          argv.push_back(0);
  
          for (int i = 0; i &lt; point_filter.argc; ++i)
          {
              std::cout &lt;&lt; argv[i] &lt;&lt; std::endl;
          }
  
          if (!lasreadopener.parse(point_filter.argc, &amp;argv[0]))
          {
              send_message("Error parsing filter parameters.");
              sig_fail();
              return;
          }
      }
  }  
  </code></pre>
  
  <p>Now this works... once. You can notice that the arguments are printed twice, first as elements of <code>LoadWorker::point_filter.args</code> vector and then as elements of the <code>vector&lt;char*&gt; argv</code>. If I set the filter and then press the load button it all works. If I then try to load another file, without changing <code>AdvancedLoadDialog::point_filter</code> at all, the arguments are disappearing. Here's an example output trying to load two files in a row.</p>
  
  <blockquote>
    <p>LoadWorker::file_filter contents:  point_filter.argc: 6
    point_filter.args:  filter
    -clip_z_above 12
    -keep_intensity 11 222 Using filter:  filter
    -clip_z_above 12
    -keep_intensity 11 222 LoadWorker::file_filter contents:  point_filter.argc: 6 point_filter.args:  filter clip_z_above 2
    keep_intensity 1 22 Using filter:  filter</p>
    
    <p>// 6 blank lines here</p>
  </blockquote>
  
  <p>To make it even more odd, during the second run each string except the first one in <code>point_filter.args</code> is missing the first character and in the <code>argv</code> they are all empty.</p>
  
  <p>Any clues whatsoever?</p>