title: How to construct template hierarchy for singly and doubly list nodes c++
body: <p>I just want to implement two types of nodes(only nodes):<br>
  A node for singly linked list and a node class for doubly linked list.<br>
  The obvious solution would be to define two separate classes:</p>
  <pre><code>template &lt;typename T&gt;
  struct SinglyNode
  {
      using node_pointer = SinglyNode&lt;T&gt;*;
      SinglyNode(T data = T{}, node_pointer next = nullptr)
          : m_data{ data },
          m_next{ next }
      {}
      T m_data;
      node_pointer m_next;
  };
  
  template &lt;typename T&gt;
  struct DoublyNode
  {
      using node_pointer = DoublyNode&lt;T&gt;*;
      DoublyNode(T data = T{}, node_pointer prev = nullptr, node_pointer next = nullptr)
          : m_data{ data },
          m_prev { prev },
          m_next{ next }
      {}
      T m_data;
      node_pointer m_prev;
      node_pointer m_next;
  };
  </code></pre>
  <p>I know that DoublyNode and SinglyNode both have data, and link to the next node(nodes aren`t of the same type, SinglyNode::m_next is of type SinglyNode* and DoublyNode::m_next is of type DoublyNode*),
  in addition DoublyNode also has link to previous node.</p>
  <p>But how can I make a hierarchy to erase/minimize code duplicate so that user could use the derived class member without the need to dynamic_cast to derived node?</p>
  <p>Note: A code snippet or a few hints will be sufficient for me.</p>