title: C++ ifstream in class error
body: <p>I've searched around a lot with this question and found a lot of questions that were similar, but I haven't managed to find a solution. I'm declaring a class:</p>
  
  <pre><code>class File {
  
      public:
              string fileName;
              std::ifstream &amp; flinstream;
              Password pass;
              //Next block to look at
              unsigned int nb;
              unsigned int sectorsLeft;
  File (string name,string passd);
  File ( );
  };
  </code></pre>
  
  <p>and a corresponding function:</p>
  
  <pre><code>File::File (string name,string passd) {
           fileName =  name;
          const char* cstr =  name.c_str();
           pass =  Password(passd);
           flinstream =  std::ifstream(cstr);
          if(!flinstream.good()) {
              string err =  "The file '";
              err.append(name);
              err.append("' could not be opened!");
              callError(err,3);
          }
      }
  </code></pre>
  
  <p>at compile-time, I get the following errors:</p>
  
  <pre><code> [0] =&gt; out.cpp: In constructor ‘File::File(std::string, std::string)’:
      [1] =&gt; out.cpp:130:3: error: uninitialized reference member ‘File::flinstream’
      [2] =&gt; In file included from /usr/include/c++/4.5/ios:39:0,
      [3] =&gt;                  from /usr/include/c++/4.5/ostream:40,
      [4] =&gt;                  from /usr/include/c++/4.5/iostream:40,
      [5] =&gt;                  from out.cpp:1:
      [6] =&gt; /usr/include/c++/4.5/bits/ios_base.h: In member function ‘std::basic_ios&lt;char&gt;&amp; std::basic_ios&lt;char&gt;::operator=(const std::basic_ios&lt;char&gt;&amp;)’:
      [7] =&gt; /usr/include/c++/4.5/bits/ios_base.h:788:5: error: ‘std::ios_base&amp; std::ios_base::operator=(const std::ios_base&amp;)’ is private
      [8] =&gt; /usr/include/c++/4.5/iosfwd:77:11: error: within this context
      [9] =&gt; /usr/include/c++/4.5/iosfwd: In member function ‘std::basic_istream&lt;char&gt;&amp; std::basic_istream&lt;char&gt;::operator=(const std::basic_istream&lt;char&gt;&amp;)’:
      [10] =&gt; /usr/include/c++/4.5/iosfwd:83:11: note: synthesized method ‘std::basic_ios&lt;char&gt;&amp; std::basic_ios&lt;char&gt;::operator=(const std::basic_ios&lt;char&gt;&amp;)’ first required here
      [11] =&gt; /usr/include/c++/4.5/iosfwd: In member function ‘std::basic_ifstream&lt;char&gt;&amp; std::basic_ifstream&lt;char&gt;::operator=(const std::basic_ifstream&lt;char&gt;&amp;)’:
      [12] =&gt; /usr/include/c++/4.5/iosfwd:111:11: note: synthesized method ‘std::basic_istream&lt;char&gt;&amp; std::basic_istream&lt;char&gt;::operator=(const std::basic_istream&lt;char&gt;&amp;)’ first required here
      [13] =&gt; /usr/include/c++/4.5/streambuf: In member function ‘std::basic_filebuf&lt;char&gt;&amp; std::basic_filebuf&lt;char&gt;::operator=(const std::basic_filebuf&lt;char&gt;&amp;)’:
      [14] =&gt; /usr/include/c++/4.5/streambuf:781:7: error: ‘std::basic_streambuf&lt;_CharT, _Traits&gt;::__streambuf_type&amp; std::basic_streambuf&lt;_CharT, _Traits&gt;::operator=(const std::basic_streambuf&lt;_CharT, _Traits&gt;::__streambuf_type&amp;) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;, std::basic_streambuf&lt;_CharT, _Traits&gt;::__streambuf_type = std::basic_streambuf&lt;char&gt;]’ is private
      [15] =&gt; /usr/include/c++/4.5/iosfwd:108:11: error: within this context
      [16] =&gt; /usr/include/c++/4.5/iosfwd: In member function ‘std::basic_ifstream&lt;char&gt;&amp; std::basic_ifstream&lt;char&gt;::operator=(const std::basic_ifstream&lt;char&gt;&amp;)’:
      [17] =&gt; /usr/include/c++/4.5/iosfwd:111:11: note: synthesized method ‘std::basic_filebuf&lt;char&gt;&amp; std::basic_filebuf&lt;char&gt;::operator=(const std::basic_filebuf&lt;char&gt;&amp;)’ first required here
      [18] =&gt; out.cpp: In constructor ‘File::File(std::string, std::string)’:
      [19] =&gt; out.cpp:134:36: note: synthesized method ‘std::basic_ifstream&lt;char&gt;&amp; std::basic_ifstream&lt;char&gt;::operator=(const std::basic_ifstream&lt;char&gt;&amp;)’ first required here
      [20] =&gt; out.cpp: In constructor ‘File::File()’:
      [21] =&gt; out.cpp:142:3: error: uninitialized reference member ‘File::flinstream’
      [22] =&gt; out.cpp: In member function ‘File&amp; File::operator=(const File&amp;)’:
      [23] =&gt; out.cpp:51:12: error: non-static reference member ‘std::ifstream&amp; File::flinstream’, can't use default assignment operator
      [24] =&gt; out.cpp: In function ‘int main(int, char**)’:
      [25] =&gt; out.cpp:166:57: note: synthesized method ‘File&amp; File::operator=(const File&amp;)’ first required here
  )
  </code></pre>
  
  <p>I've gathered that <code>ifstream</code> is rather particular with the assignment and all, but I've no idea how to include it in a class. Thanks in advance for your help!</p>
  
  <p>EDIT: I've tried several permutations of the above class, such as using a normal variable:</p>
  
  <pre><code>std::ifstream flinstream;
  </code></pre>
  
  <p>As well as using the <code>open()</code> function suggested:</p>
  
  <pre><code>flinstream.open(cstr);
  </code></pre>
  
  <p>However, the error remains the same.</p>