title: forward declaration and namespaces (c++)
body: <p>My Problem:</p>
  
  <p>Got two classes, class A and B, so i got A.h and A.cpp and B.h and B.cpp.
  A needs to know B and B needs to know A. I solved it the following way (i don't know why it has to be so...)</p>
  
  <p>A.h:</p>
  
  <pre><code>#include "B.h"
  class A{ ... 
  </code></pre>
  
  <p>A.cpp:</p>
  
  <pre><code>#include "A.h"
  </code></pre>
  
  <p>B.h:</p>
  
  <pre><code>#include "A.h"
  class A; // forward declaration
  class B { ... 
  </code></pre>
  
  <p>B.cpp:</p>
  
  <pre><code>#include "B.h"
  </code></pre>
  
  <p>I used one forward declaration and it works.</p>
  
  <p>The Problem is, that both classes need to be in the namespace "ui". Or at least I think this is the meaning:</p>
  
  <p>A.h:</p>
  
  <pre><code>#include "B.h"
  namespace ui{
    class A;
  }
  
  class A{ ... 
  </code></pre>
  
  <p>B.h:</p>
  
  <pre><code>#include "A.h"
  namespace ui{
    class B;
  }
  
  class B{ ... 
  </code></pre>
  
  <p>This doesn't work anymore. What do I have to do now to make it work again with namespace and forward declaration?</p>
  
  <p>Both have to be in this namespace. I'm working with Qt and the lines "namespace ui{" etc. are needed. And both classes need to know each other.
  I already tried just to make this:</p>
  
  <pre><code>namespace ui{
   class A;
   class B;
  }
  </code></pre>
  
  <p>in both headers, but this doesn't work...</p>
  
  <p>Btw: All Header-Files also got the "ifndef"-mechanism.</p>