Friend functions not being able to access private members
<p>My ostream friend function works correctly but my ofstream nor ifstream work correctly as the errors that are given state that the different private members cannot be accessed through the ofstream or ifstream functions. Please help.</p>

<pre><code>class Module 
{ 
public: 
   Module() = default; 
   explicit Module(const string&amp; purpose, const string&amp; id)  
   {  
      this-&gt;purpose = purpose; 
      this-&gt;id = id; 
   } 
   explicit Module(const string&amp; purpose) { this-&gt;purpose = purpose; } 
   ~Module() { } 

   virtual void setCrew( ) = 0; 
   virtual void display( ) = 0; 
   void addCrew(Crew c) { crew_list.push_back(c); } 
   void setPowerReq(double power) { this-&gt;power = power; }  
   void setMaxCrew(int max_crew) { this-&gt;max_crew = max_crew; } 

   string getPurpose( ) { return purpose; } 
   string getId( ) { return id; } 
   int getNumberOfCrew( ) { return number_of_crew; } 
   int getMaxCrew( ) { return max_crew; } 
   double getPower( ) { return power; }  

   friend ostream&amp; operator &lt;&lt; ( ostream&amp; os, const Module&amp; m ); 
   friend ofstream&amp; operator &lt;&lt; ( ofstream os, const Module&amp; m ); 
   friend ifstream&amp; operator &gt;&gt; ( ifstream is, Module&amp; m ); 

private: 
   static string purpose; 
   string id = "unknown"; 
   int number_of_crew = 0; 
   int max_crew = 0; 
   double power = 0; 
   vector&lt;Crew&gt; crew_list;  
};

#include "module.h"

string Module::purpose = "Module";

ofstream&amp; operator &lt;&lt; ( ofstream&amp; os, const Module&amp; m )
{
  os &lt;&lt; m.purpose &lt;&lt; endl
      &lt;&lt; m.id &lt;&lt; endl
      &lt;&lt; m.number_of_crew &lt;&lt; endl
      &lt;&lt; m.max_crew &lt;&lt; endl
      &lt;&lt; m.power &lt;&lt; endl;
   for ( auto i : m.crew_list )
   {
      os &lt;&lt; i &lt;&lt; endl;
   }
   return os;
}

ifstream&amp; operator &gt;&gt; ( ifstream&amp; is, Module&amp; m )
{
   getline( is, m.purpose );
   return is;
}

ostream&amp; operator &lt;&lt; ( ostream&amp; os, const Module&amp; m )
{
   os &lt;&lt; m.purpose &lt;&lt; endl
      &lt;&lt; m.id &lt;&lt; endl
      &lt;&lt; m.number_of_crew &lt;&lt; endl
      &lt;&lt; m.max_crew &lt;&lt; endl
      &lt;&lt; m.power &lt;&lt; endl;
   for ( auto i : m.crew_list )
   {
      os &lt;&lt; i &lt;&lt; endl;
   }
   return os;
}
</code></pre>