title: Initializing a reference variable in a class constructor
body: <p>So I'm still kind of figuring out the semantics of C++ references here.</p>
  
  <p>I have a class that has a reference as a member, and I initialize the reference in the constructor.</p>
  
  <pre><code>template&lt;class T&gt;
  class AVLNode {
  
  private:
         T &amp; data;
  public:
         AVLNode(T &amp; newData) {
              data = newData;
          }
  };
  </code></pre>
  
  <p>But I get this error on the constructor line:</p>
  
  <pre><code>error: uninitialized reference member ‘AVLNode&lt;int&gt;::data’ [-fpermissive]
  </code></pre>
  
  <p>I don't get this, I initialize the reference as soon as the class is constructed so there shouldn't be a problem with the reference being uninitialized right?</p>