title: Forward declaration of class in header causes incomplete type
body: <p>I had a look at <a href="https://stackoverflow.com/questions/4757565/c-forward-declaration">forward declaring</a> to get around the compile error " error: variable or field ‘mov_avg’ declared void".<br> Following scenario: There is one data_proc.cpp having the main() including a custom header <code>my_mov_avg.h</code>, which embeds the function <code>mov_avg(shared)</code>.  Furthermore the header function accesses <code>class cl_shared</code> inside the main-file. The files look like:<br></p>
  
  <pre><code>#include &lt;string.h&gt;     //c++ headers
  #include &lt;iostream&gt; //red?
  
  #include "my_mov_avg.h" //outsourced function
  
  using namespace std;
  
  /* class accessed from header*/
  class cl_shared {
  public:
      //constructor 
      cl_shared() { };
  
      int getint() {
          return a;
      }
  private:
      int a;
  };
  cl_shared shared; //class object
  
  /*main calling function inside header*/
  int main(int argc, char **argv){
      mov_avg(shared);
      getchar();
      return 0;
  }
  </code></pre>
  
  <p>The header <code>my_mov_avg.h</code> file:</p>
  
  <pre><code>//in .h
  void say();
  void mov_avg();
  
  //in .cpp
  #include &lt;string.h&gt;     
  #include &lt;iostream&gt; 
  #include "my_mov_avg.h"
  
  
  void say() {
      std::cout &lt;&lt; "Ohai from another .cpp file!";
  }
  class cl_shared; //Forward declaration
  void mov_avg(cl_shared shared){
          std::cout&lt;&lt;" int from class: "&lt;&lt; shared.getint()&lt;&lt; std::endl; 
  }
  </code></pre>
  
  <p>Now as I forward declared so that the function argument type is defined I got this compile error:</p>
  
  <pre><code> error: ‘shared’ has incomplete type
   void mov_avg(cl_shared shared){
        ^
   /my_mov_avg.cpp:9:11: error: forward declaration of ‘class cl_shared’
   class cl_shared;
         ^
  </code></pre>
  
  <p>How to get it to compile and is it bad design to access the class cl_shared from the header?<br> What I try to achieve is to repeatedly access data (here broken down to a changing int) from where the header-function was called. <br> I could break out the <code>class cl_shared</code> into a separate header file and include it in both but I'm not sure, additionally it causes another header file(which might not be necessary).<br>
  <strong>EDIT</strong> added argument inside the my_mov_avg.h <br>
   <code>void mov_avg(cl_shared shared);</code> but still causes:</p>
  
  <pre><code>my_mov_avg.h:3:14: error: variable or field ‘mov_avg’ declared void
   void mov_avg(cl_shared shared);
  </code></pre>
  
  <p>sidenote: a quick and dirty hack to break down one big cpp-file is to place the function into a seperate cpp and place <code>#include "seperate.cpp"</code> where the function originally was. Use only with simple programs.</p>