title: error: does not name a type, when setting pointer to class to 0
body: <p>I am trying get the hang of basics of C++, and I am stuck on this piece of code: </p>
  
  <pre><code>#include&lt;iostream&gt;
  
  using namespace::std;
  
  class Node
  {
  public:
    int x;
    Node *ptr_next;
  
  };
  
  class LinkedList
  {
  public:
    Node *head;
    head = 0; //If I comment out this line the code compiles
  };
  
  int main()
  {
    LinkedList linked_list;
    return 0;
  }
  </code></pre>
  
  <p>When I run the above I get this error:</p>
  
  <pre><code>error: ‘head’ does not name a type
  </code></pre>
  
  <p>I don't understand why I can't set <code>head</code> to <code>0</code>; I looked at <a href="https://stackoverflow.com/questions/2133250/does-not-name-a-type-error-in-c">this question</a> and it seemed that a possible cause for the above error is compiler not knowing what referenced class (in my case <code>Node</code> is). However, this should not be the case here because if I just declare <code>head</code> to be a pointer to <code>Node</code> my code runs fine. It's when I try to set <code>head</code> to <code>0</code> the above error is raised. What am I missing?</p>
  
  <p>If I ignore the <code>LinkedList</code> class, and change <code>main</code> to:</p>
  
  <pre><code>int main()
  {
    Node *head;
    head = 0;
    return 0;
  }
  </code></pre>
  
  <p>The code compiles fine. So it is some interaction between <code>Node</code> and <code>LinkedList</code> that I am missing. What is it?</p>