title: Can't pass an ifstream pointer in a vector through a function
body: <p>I'm trying to make a program that'll generate a two-dimensional city. I'm taking a file with the width and length of a building (predefined) from a file and passing it through a function (place_object) that'll put it in its place in the text file.</p>
  
  <p>That works all fine and well, at least it did when I just passed a singular <code>ifstream</code> object through the function. Now I have a vector of pointers to <code>ifstream</code> objects, theoretically pointing to each house object I have because you cannot simply pass an <code>ifstream</code> object into a vector.</p>
  
  <p>I keep getting errors in trying to pass these pointers through a function.</p>
  
  <p>I have a hard time with understanding pointers, although I understand passing by reference perfectly fine.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;vector&gt;
  #include &lt;conio2.h&gt;
  #include &lt;constream&gt;
  
  using namespace std;
  
  //...Structures...
  struct Data
  {
      int width;
      int height;
  };
  
  //...Global Variables...
  
  //...Function Prototypes...
  void set_data(Data&amp;);
  void init_map(vector&lt; vector&lt;char&gt; &gt;&amp;, Data&amp;);
  void transfer_to_file(vector&lt; vector&lt;char&gt; &gt;&amp;, ofstream&amp;, Data&amp;);
  void place_object(int,int,ifstream*&amp;,vector&lt; vector&lt;char&gt; &gt;&amp;);
  
  int main()
  {
      //...Path Address Files...
      ofstream m("What_You_Need/map.txt");
      ifstream house_files("Data/File_Paths/houses.dat");
      //...Regular Variables...
      Data d;
      vector&lt; vector&lt;char&gt; &gt; map;
  
      //...Structures...
      vector&lt;ifstream*&gt; houses;
  
  
      //...Load Vectors...
      string path;
      house_files &gt;&gt; path;
      while(!house_files.eof())
      {
          ifstream ifstr(path.c_str());
          houses.push_back(&amp;ifstr);
          house_files &gt;&gt; path;
      }
  
      //...Get Size...
      do
      {
          cout &lt;&lt; "What's the map size? (HxW): ";
          cin &gt;&gt; d.width;
          cin.ignore(10,'x');
          cin &gt;&gt; d.height;
          if(cin.fail())
          {
              cin.clear();
              cin.ignore();
          }       
      }
      while((d.width &lt; 300 || d.height &lt; 300) || cin.fail());
  
      init_map(map,d);
  
      //...TEST CODE HERE...
      //...Structure Files...
      getch();
      place_object(3,3,houses[0],map);
      transfer_to_file(map,m,d);
  
      //...File Close...
      house_files.close();
      m.close();
  
      //...Misc...
      return 0;
  }
  
  //...Funtions...
  void set_data(Data &amp;d)
  {
  
  }
  
  void init_map(vector&lt; vector&lt;char&gt; &gt; &amp;map, Data &amp;d)
  {
      for (int i = 0 ; i &lt; d.height ; i++)
      {
          vector&lt;char&gt; row; // Create an empty row
          for (int j = 0 ; j &lt; d.width ; j++)
          {
              row.push_back('.'); // Add an element (column) to the row
          }
          map.push_back(row); // Add the row to the main vector
      }
  }
  
  void transfer_to_file(vector&lt; vector&lt;char&gt; &gt; &amp;map, ofstream &amp;o, Data &amp;d)
  {
      for(int i = 0 ; i &lt; d.height ; i++)
      {
          for(int j = 0 ; j &lt; d.width ; j++)
              o &lt;&lt; map[i][j];
          o &lt;&lt; "\n";
      }
  }
  
  void place_object(int x, int y, ifstream *&amp;is, vector&lt; vector&lt;char&gt; &gt; &amp;map)
  {
      int width;
      int height;
      is &gt;&gt; width &gt;&gt; height;
      is.ignore(100,'\n');
  
      for(int i = 0 ; i &lt; height ; i++)
      {
          string s;
          getline(is,s);
          for(int j = 0 ; j &lt; width ; j++)
          {
              map[i+y-1][j+x-1] = s[j];
          }
          cout &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>Errors: (With new code that uses the "new" operator):</p>
  
  <pre><code>C:\Users\r_bur_000\Documents\#PROGRAMS\Map_Generator\main.cpp   In function 'void place_object(int, int, std::ifstream*&amp;, std::vector&lt;std::vector&lt;char&gt; &gt;&amp;)':
  111 8   C:\Users\r_bur_000\Documents\#PROGRAMS\Map_Generator\main.cpp   [Error] invalid operands of types 'std::ifstream* {aka std::basic_ifstream&lt;char&gt;*}' and 'int' to binary 'operator&gt;&gt;'
  112 5   C:\Users\r_bur_000\Documents\#PROGRAMS\Map_Generator\main.cpp   [Error] request for member 'ignore' in 'is', which is of pointer type 'std::ifstream* {aka std::basic_ifstream&lt;char&gt;*}' (maybe you meant to use '-&gt;' ?)
  117 15  C:\Users\r_bur_000\Documents\#PROGRAMS\Map_Generator\main.cpp   [Error] no matching function for call to 'getline(std::ifstream*&amp;, std::string&amp;)'
  117 15  C:\Users\r_bur_000\Documents\#PROGRAMS\Map_Generator\main.cpp   [Note] candidates are:
  53  0   c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\string In file included from c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\string
  40      c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\bits\locale_classes.h                   from c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\bits\locale_classes.h
  41      c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\bits\ios_base.h                     from c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\bits\ios_base.h
  42      c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\ios                     from c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\ios
  38      c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\ostream                     from c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\ostream
  39      c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\iostream                    from c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\iostream
  1       C:\Users\r_bur_000\Documents\#PROGRAMS\Map_Generator\main.cpp                    from main.cpp
  1068    5   c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\bits\basic_string.tcc  [Note] template&lt;class _CharT, class _Traits, class _Alloc&gt; std::basic_istream&lt;_CharT, _Traits&gt;&amp; std::getline(std::basic_istream&lt;_CharT, _Traits&gt;&amp;, std::basic_string&lt;_CharT, _Traits, _Alloc&gt;&amp;, _CharT)
  1068    5   c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\bits\basic_string.tcc  [Note] template argument deduction/substitution failed:
  117 15  C:\Users\r_bur_000\Documents\#PROGRAMS\Map_Generator\main.cpp   [Note] mismatched types 'std::basic_istream&lt;_CharT, _Traits&gt;' and 'std::ifstream* {aka std::basic_ifstream&lt;char&gt;*}'
  52  0   c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\string In file included from c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\string
  40      c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\bits\locale_classes.h                   from c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\bits\locale_classes.h
  41      c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\bits\ios_base.h                     from c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\bits\ios_base.h
  42      c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\ios                     from c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\ios
  38      c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\ostream                     from c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\ostream
  39      c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\iostream                    from c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\iostream
  1       C:\Users\r_bur_000\Documents\#PROGRAMS\Map_Generator\main.cpp                    from main.cpp
  2793    5   c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\bits\basic_string.h    [Note] template&lt;class _CharT, class _Traits, class _Alloc&gt; std::basic_istream&lt;_CharT, _Traits&gt;&amp; std::getline(std::basic_istream&lt;_CharT, _Traits&gt;&amp;, std::basic_string&lt;_CharT, _Traits, _Alloc&gt;&amp;)
  2793    5   c:\program files (x86)\dev-cpp\mingw32\lib\gcc\mingw32\4.8.1\include\c++\bits\basic_string.h    [Note] template argument deduction/substitution failed:
  117 15  C:\Users\r_bur_000\Documents\#PROGRAMS\Map_Generator\main.cpp   [Note] mismatched types 'std::basic_istream&lt;_CharT, _Traits&gt;' and 'std::ifstream* {aka std::basic_ifstream&lt;char&gt;*}'
  28      C:\Users\r_bur_000\Documents\#PROGRAMS\Map_Generator\Makefile.win   recipe for target 'main.o' failed
  </code></pre>