title: How to fix "invalid use of incomplete type" in c++
body: <p>I wanted to make a friendship between 2 classes by using the method from one class. Even I looked into different tutorials and books and I can't make it works. </p>
  
  <p><strong>Edit</strong>::
  It works in one file, but I want to make it in separated files - what unfortunately can't do:</p>
  
  <p>Tbase_in_memory.h:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#ifndef FRENDY_TBASE_IN_MEMORY_H
  #define FRENDY_TBASE_IN_MEMORY_H
  
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  
  class base;
  
  class Tbase_in_memory
  {
  public:
      Tbase_in_memory(int = 2);
      ~Tbase_in_memory();
      void read_to_arrays(base &amp; b);
  
  private:
      std::string *name;
      double      *price_tag;
      int         *code;
      char        *type;
      int         _size;
  };
  
  #endif
  </code></pre>
  
  <p>Tbase_in_memory.cpp:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include "Tbase_in_memory.h"
  
  using namespace std;
  
  class base;
  Tbase_in_memory::Tbase_in_memory(int s)
  {
      _size = s;
      name = new string[_size];
      price_tag = new double[_size];
      code = new int[_size];
      type = new char[_size];
  }
  
  Tbase_in_memory::~Tbase_in_memory()
  {
      delete[] name;
      delete[] price_tag;
      delete[] code;
      delete[] type;
  }
  
  void Tbase_in_memory::read_to_arrays(base &amp; b)
  {
      string line;
      while (getline(b.file, line)) {
          cout &lt;&lt; line;
      }
  }
  </code></pre>
  
  <p>base.h:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#ifndef FRENDY_BASE_H
  #define FRENDY_BASE_H
  
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  #include "Tbase_in_memory.h"
  
  class base
  {
  public:
      base(std::string = "...");
      ~base();
      friend void Tbase_in_memory::read_to_arrays(base &amp; b);
  private:
      std::fstream    file;
      std::string     f_name;
  };
  
  #endif
  
  </code></pre>
  
  <p>base.cpp</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include "base.h"
  
  using namespace std;
  
  base::base(string n)
  {
      f_name = n;
      file.open(f_name, ios::in);
  
      if (!file.good()) {
          cout &lt;&lt; "Error";
          cout &lt;&lt; string(38, '-');
          exit(0);
      }
  }
  
  base::~base()
  {
      file.close();
  }
  </code></pre>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include "Tbase_in_memory.h"
  #include "base.h"
  
  using namespace std;
  
  int main()
  {
      base b("/home/Sempron/Desktop/code");
      Tbase_in_memory a;
      a.read_to_arrays(b);
      return 0;
  }
  </code></pre>
  
  <p>I got errors:</p>
  
  <pre><code>"error: invalid use of incomplete type ‘class base’
       while (getline(b.file, line)) {". 
  
  "forward declaration of ‘class base’
       class base;"
  </code></pre>