title: using fstream object created as class member
body: <p>I have an fstream object declared in my class like this (just an example):</p>
  
  <pre><code>class Asd {
  
    public:
    Asd();
  
    private:
    std::fstream stream;
  
  };
  </code></pre>
  
  <p>Now when the constructor is called I want to specify the fstream parameters like this</p>
  
  <pre><code>Asd::Asd() {
  
    this-&gt;stream = std::fstream(file, std::fstream::in);
  
  }
  </code></pre>
  
  <p>and then use that stream in all class functions that I have, but it doesn't work. One error VS is giving me is:</p>
  
  <pre><code>no accessible path to private member declared in virtual base 'std::basic_ios&lt;_Elem,_Traits&gt;'
  </code></pre>
  
  <p>So I read up on that and all I could find is that I can't (or rather: shouldn't) copy a stream and indeed I don't even want to do that. Someone said one could add this to the constructor:</p>
  
  <pre><code>Asd::Asd() : stream(file, std::fstream::in) {
  
    ...
  
  }
  </code></pre>
  
  <p>but it prints the same error and I don't know what to do... Also someone else said I have to reference the object but I don't know how?? I just want this to work but I can't figure it out :(</p>
  
  <p>Edit: this is the full error message</p>
  
  <pre><code>1&gt;c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(860): error C2249: 'std::basic_ios&lt;_Elem,_Traits&gt;::operator =' : no accessible path to private member declared in virtual base 'std::basic_ios&lt;_Elem,_Traits&gt;'
  1&gt;          with
  1&gt;          [
  1&gt;              _Elem=char,
  1&gt;              _Traits=std::char_traits&lt;char&gt;
  1&gt;          ]
  1&gt;          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ios(177) : see declaration of 'std::basic_ios&lt;_Elem,_Traits&gt;::operator ='
  1&gt;          with
  1&gt;          [
  1&gt;              _Elem=char,
  1&gt;              _Traits=std::char_traits&lt;char&gt;
  1&gt;          ]
  1&gt;          This diagnostic occurred in the compiler generated function 'std::basic_istream&lt;_Elem,_Traits&gt; &amp;std::basic_istream&lt;_Elem,_Traits&gt;::operator =(const std::basic_istream&lt;_Elem,_Traits&gt; &amp;)'
  1&gt;          with
  1&gt;          [
  1&gt;              _Elem=char,
  1&gt;              _Traits=std::char_traits&lt;char&gt;
  1&gt;          ]
  1&gt;c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(604): error C2249: 'std::basic_ios&lt;_Elem,_Traits&gt;::operator =' : no accessible path to private member declared in virtual base 'std::basic_ios&lt;_Elem,_Traits&gt;'
  1&gt;          with
  1&gt;          [
  1&gt;              _Elem=char,
  1&gt;              _Traits=std::char_traits&lt;char&gt;
  1&gt;          ]
  1&gt;          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ios(177) : see declaration of 'std::basic_ios&lt;_Elem,_Traits&gt;::operator ='
  1&gt;          with
  1&gt;          [
  1&gt;              _Elem=char,
  1&gt;              _Traits=std::char_traits&lt;char&gt;
  1&gt;          ]
  1&gt;          This diagnostic occurred in the compiler generated function 'std::basic_ostream&lt;_Elem,_Traits&gt; &amp;std::basic_ostream&lt;_Elem,_Traits&gt;::operator =(const std::basic_ostream&lt;_Elem,_Traits&gt; &amp;)'
  1&gt;          with
  1&gt;          [
  1&gt;              _Elem=char,
  1&gt;              _Traits=std::char_traits&lt;char&gt;
  1&gt;          ]
  </code></pre>