title: c++ pushing dereferenced objects to vector
body: <p>I'm making a function to take in a reference to a path on the filesystem and recursively add file names to a vector. But first I have to be able to add paths to a vector.</p>
  
  <p>what is wrong with this method?</p>
  
  <pre><code>namespace filesys = boost::filesystem;
  </code></pre>
  
  <p>Method:</p>
  
  <pre><code>void recursive_file_list(filesys::path &amp; root_path, vector&lt;filesys::path&gt; &amp; paths) {
      paths-&gt;push_back(*root_path);    // line 14
  
      // TODO: add more logic to actually recurse through file system
      // for now just add root_path (even though root_path is path of directory, not file)
  }
  </code></pre>
  
  <p>And I call it like so:</p>
  
  <pre><code>    int main(int argc, char* argv[]) {
  
          // Use the command line arguments
          filesys::path abs_path;    // line 23
          if ( argc &gt; 1 )
              // Make the system complete this path to absolute path
              abs_path = filesys::system_complete( filesys::path( argv[1] ) );
          else {
              // If no arguments given
              cout &lt;&lt; "usage:   list_files [path]" &lt;&lt; endl;
              exit(1);
          }
  
          // Is this a valid path?
          if (!filesys::exists( abs_path )) {
              cout &lt;&lt; "The path you have specified does not exist." &lt;&lt; endl; 
              exit(2);
          }
  
          // If this is a directory
          vector&lt;filesys::path&gt; filepaths();   
          if (filesys::is_directory( abs_path )) {
              cout &lt;&lt; "You have specified a directory." &lt;&lt; endl;
              recursive_file_list(&amp;abs_path, &amp;filepaths);
          }
  
          else {
              cout &lt;&lt; "You have specified a file." &lt;&lt; endl;
          }
      }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>list_files.cpp: In function 'void recursive_file_list(boost::filesystem3::path&amp;, std::vector&lt;boost::filesystem3::path, std::allocator&lt;boost::filesystem3::path&gt; &gt;&amp;)':
  list_files.cpp:14: error: base operand of '-&gt;' has non-pointer type 'std::vector&lt;boost::filesystem3::path, std::allocator&lt;boost::filesystem3::path&gt; &gt;'
  list_files.cpp:14: error: no match for 'operator*' in '*root_path'
  list_files.cpp: In function 'int main(int, char**)':
  list_files.cpp:43: error: invalid initialization of non-const reference of type 'boost::filesystem3::path&amp;' from a temporary of type 'boost::filesystem3::path*'
  list_files.cpp:13: error: in passing argument 1 of 'void recursive_file_list(boost::filesystem3::path&amp;, std::vector&lt;boost::filesystem3::path, std::allocator&lt;boost::filesystem3::path&gt; &gt;&amp;)'
  </code></pre>
  
  <p>I don't understand - I'm passing it by reference and then dereferencing it to add it...not sure what I'm doing wrong.</p>