title: C++ unknown type name due to circular dependency
body: <p>C++ newbie here. I currently have two classes that depend on one another. Class A composes a data member of Class B, while Class B uses pointers to Class A. </p>
  
  <pre><code>// main.cpp 
  #include "A.hpp"
  
  // A.hpp
  #pragma once
  #include "B.hpp"
  
  class A {
      private:
          const B obj;
  };
  
  
  // B.hpp
  #pragma once
  #include "A.hpp"
  
  // forward declaration
  class A;
  using T = A;
  
  class B {
      private:
          T* t_obj;
  };
  </code></pre>
  
  <p>My understanding is that the preprocessor will enter <code>A.hpp</code> first, then enter <code>B.hpp</code> immediately. It will not be able to enter <code>A.hpp</code> again because of <code>#pragma once</code>, and will resume with <code>B.hpp</code>. Then it will hit the forward declaration and so <code>class B</code> should be OK. Then, <code>A.hpp</code> will resume and <code>class A</code> should be OK.</p>
  
  <p>However, the compilation error I get is something like:</p>
  
  <pre><code> ./A.hpp:5: error: unknown type name 'B'
          const B obj;
  </code></pre>
  
  <p>Any sort of insight would be appreciated. Thank you.</p>