title: Forward declaration of returned type of function
body: <p>As this <a href="https://stackoverflow.com/a/553869/3222702">answer</a> suggests, I know that it's allowed to use incomplete types as a return value in function's declaration. So I wrote the following code:</p>
  
  <p><strong>Obj.h</strong></p>
  
  <pre><code>class Obj {
      int x;
  };
  </code></pre>
  
  <p><strong>f.h</strong></p>
  
  <pre><code>class Obj;
  Obj f();
  </code></pre>
  
  <p><strong>f.cpp</strong></p>
  
  <pre><code>#include "Obj.h"
  
  Obj f() {
      return Obj();
  }
  </code></pre>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code>#include "f.h"
  int main() {
      f();
      return 0;
  };
  </code></pre>
  
  <p>Compiling this code with the following compiler:</p>
  
  <p><code>g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)</code> </p>
  
  <p>using the following compilation command:</p>
  
  <pre><code>g++ *.cpp
  </code></pre>
  
  <p>gives the following error:</p>
  
  <pre><code>main.cpp: In function 'int main()':
  main.cpp:4:7: error: invalid use of incomplete type 'class Obj'
       f();
         ^
  f.h:1:7: error: forward declaration of 'class Obj'
   class Obj;
         ^
  </code></pre>
  
  <p>So the compiler is not allowing using incomplete type as a return value in a function's declaration. What's the explanation?</p>