title: Doubly Linked List Implementation with Pointers C++
body: <p>I am currently teaching myself C++ and am attempting to implement a doubly-linked list in C++ using pointers which is partially complete.  I am aware that the code currently fails to deal with dangling nodes or output errors, both of which I will implement next.  However, the code should atleast be able to construct a list object and add elements to it.  Currently, I am getting an error when I attempt to call a constructor for the list, which says that I am requesting a conversion from LinkedList* to non scalar type LinkedList.  Why is my list being declared as a pointer?  Any help would be much appreciated, thank you!</p>
  
  <pre><code>LinkedList.h
  #ifndef LINKEDLIST_H
  #define LINKEDLIST_H
  
  struct dataElement {
    int key;
    int id;
  };
  
  struct Node
  {
      dataElement data;
      Node* next;
      Node* prev;
  };
  
  
  class LinkedList
  {
  public:
      /** Default constructor */
      LinkedList();
      /** Default destructor */
      virtual ~LinkedList();
      void addAtFront(int newElement);
      void addAtBack(int newElement);
      int removeTop();
      int removeBottom();
      int getTop();
      int getBottom();
      int findKey(int keyToFind);
  protected:
  private:
      Node* head;
      Node* tail;
      int size;
  };
  
  #endif // LINKEDLIST_H
  
  
  LinkedList.cpp
  #include "LinkedList.h"
  #include &lt;iostream&gt;
  #include &lt;stdlib.h&gt;
  
  
  LinkedList::LinkedList()
  {
  size = 0;
  }
  
  LinkedList::~LinkedList()
  {
  //dtor
  }
  
  void LinkedList::addAtFront(int newElement)
  {
  if (size == 0)
  {
      Node temp;
      temp.data.id = newElement;
      temp.data.key = 0;
      head = &amp;temp;
      tail = &amp;temp;
      ++size;
  }
  else
  {
      Node temp;
      temp.data.id = newElement;
      temp.data.key = size;
      temp.next = head;
      head-&gt;prev = &amp;temp;
      head = &amp;temp;
      ++size;
  }
  }
  
  void LinkedList::addAtBack(int newElement)
  {
  if (size == 0)
  {
      Node temp;
      temp.data.id = newElement;
      temp.data.key = 0;
      head = &amp;temp;
      tail = &amp;temp;
      ++size;
  }
  else
  {
      Node temp;
      temp.data.id = newElement;
      temp.data.key = 0;
      tail-&gt;next = &amp;temp;
      temp.prev = tail;
      tail = &amp;temp;
      ++size;
  }
  }
  
  LinkedListTest.cpp
  #include "LinkedListTest.h"
  #include "LinkedList.h"
  
  int main()
  {
  LinkedList list = new LinkedList();
  list.addAtFront(0);
  }
  </code></pre>