title: Is using #include partway through a Class declaration bad practice?
body: <p>So, while working on a binary search tree (BST) class, I implemented a nested Node class within the BST's header file. As the Node class grew I wanted to declutter said header file, so I moved the Node class to a new header file called Node.h (forgoing a <code>#pragma once</code>) then used <code>#include &quot;Node.h&quot;</code> in the same place where the class had originally been. I then moved the Node's method definitions from BST.cpp to a new Node.cpp file (using <code>#include &quot;BST.h&quot;</code> not <code>#include &quot;Node.h&quot;</code>). Now with a couple of changes to my makefile, this all looks like it compiles exactly the same.</p>
  <p><strong>Would this be considered bad practice? Are there concerns regarding compilation or maintainability? Or is it just a matter of convention? What are some alternate ways to get the same results? (see note at the bottom)</strong></p>
  <p>Additional notes:</p>
  <p>I went from:</p>
  <pre class="lang-cpp prettyprint-override"><code>//BST.h
  #include &quot;BSTInterface.h&quot;
  #include &quot;NodeInterface.h&quot;
  
  class BST : public BSTInterface
  {
  protected:
      class Node : public NodeInterface
      {
          ...
      }
      ...
  }
  </code></pre>
  <p>to:</p>
  <pre class="lang-cpp prettyprint-override"><code>//BST.h
  #include &quot;BSTInterface.h&quot;
  #include &quot;NodeInterface.h&quot;
  
  class BST : public BSTInterface
  {
  protected:
      #include &quot;Node.h&quot;
      ...
  }
  </code></pre>
  <p>&amp;</p>
  <pre class="lang-cpp prettyprint-override"><code>//Node.h
  class Node : public NodeInterface
  {
      ...
  }
  </code></pre>
  <p>This change offered a couple of advantages:</p>
  <ol>
  <li>Both header files are now much easier to read</li>
  <li>This (to my knowledge) allows me to compile both Node.cpp and BST.cpp separately</li>
  <li>This Node.h could now be included in a few different classes without conflict</li>
  </ol>
  <p>Final note: While I know that you can declare a nested class in a .h file then define it later in a .cpp file, which has all of the advantages listed above, it doesn't seem to play well with inheritance.</p>