title: Does class/function order matter in C++?
body: <p>I'm beginning to learn C++. In the IDE codeblocks, this compiles:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  struct A {};
  
  struct B {
      A a;
  }
  
  void hi() {
      cout &lt;&lt; "hi" &lt;&lt; endl;
  }
  
  int main() {
      hi();
      return 0;
  }
  </code></pre>
  
  <p>But this doesn't:</p>
  
  <pre><code>struct B {
      A a;
  }
  
  struct A {};
  
  int main() {
      hi();
      return 0;
  }
  
  void hi() {
      cout &lt;&lt; "hi" &lt;&lt; endl;
  }
  </code></pre>
  
  <p>It gives me the errors:</p>
  
  <pre><code>error: 'A' does not name a type
  error: 'hi' was not declared in this scope
  </code></pre>
  
  <p>Should class/function order matter in C++? I thought it doesn't. Please clarify the issue.</p>