title: Inheritance with Nodes in C++
body: <p>I'm writing a doubly linked list in C++ and have a class <code>Node</code> which I'm using for a singly linked list. Below shows the definition of the class.</p>
  
  <blockquote>
    <p>Node.h</p>
  </blockquote>
  
  <pre><code>#ifndef NODE_H
  #define NODE_H
  
  template &lt;class T&gt;
  class Node {
      public:
          Node&lt;T&gt;() { next = nullptr; } 
          Node&lt;T&gt;(T init) { data = init; next = nullptr; }
  
          void setData(T newData) { data = newData; }
          void setNext(Node&lt;T&gt; *nextNode) { next = nextNode; }
  
          const T getData() { return data; }
          Node&lt;T&gt; *getNext() { return next; }
      private:
          T data;
          Node&lt;T&gt; *next;
  };
  
  #endif
  </code></pre>
  
  <p>Obviously the main difference between a singly linked list and doubly linked list is a pointer to the previous <code>Node</code>, so I'm trying to inherit everything from the <code>Node</code> class in a new class and simply add a <code>prev</code> attribute:</p>
  
  <blockquote>
    <p>DoublyLinkedList.h</p>
  </blockquote>
  
  <pre><code>#ifndef DOUBLY_LINKEDLIST_H
  #define DOUBLY_LINKEDLIST_H
  
  #include "Node.h"
  
  template &lt;class T&gt;
  class DLLNode : public Node {
      public:
          // Inherit default constructor from Node and set prev to nullptr;
          DLLNode&lt;T&gt;() : Node&lt;T&gt;(), prev() {}
          // Inherit constructor from Node and set prev to nullptr;
          DLLNode&lt;T&gt;(T init) : Node&lt;T&gt;(init), prev() {}
  
          Node&lt;T&gt; *getPrev() { return prev; }
      private:
          Node&lt;T&gt; *prev;
  };
  
  /*
      TODO: Implement doubly linked list class
  */
  
  #endif
  </code></pre>
  
  <p>My driver is, simply, the following:</p>
  
  <blockquote>
    <p>driver.cc</p>
  </blockquote>
  
  <pre><code>#include &lt;iostream&gt;
  #include "DoublyLinkedList.h"
  
  int main() 
  {
      DLLNode&lt;int&gt; test;
  
      return 0;
  }
  </code></pre>
  
  <p>When I compile, I get the following errors:</p>
  
  <pre><code>./DoublyLinkedList.h:7:24: error: expected class name
  class DLLNode : public Node {
                         ^
  ./DoublyLinkedList.h:9:18: error: type 'Node&lt;int&gt;' is not a direct or virtual base of 'DLLNode&lt;int&gt;'
                  DLLNode&lt;T&gt;() : Node&lt;T&gt;(), prev() {}
                                 ^~~~~~~
  driver.cc:6:15: note: in instantiation of member function 'DLLNode&lt;int&gt;::DLLNode' requested here
          DLLNode&lt;int&gt; test;
  </code></pre>
  
  <p>I don't understand why the class <code>Node</code> isn't being recognized as a class as my compiler has claimed by the first error. Any tips would be greatly appreciated. </p>
  
  <p>My compiler is <code>Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)</code></p>