title: Accessing a member of struct in class, LinkedList Node
body: <p>So I am just starting out learning LinkedLists for C++. I know C+ has a library for them but I'm trying to focus on LinkedLists. An exercise I saw asks you to design a linked list class with 2 member functions and a default constructor: add, isMember, and the LinkedList() constructor. Add function adds a new node to the front of the list. isMember tests to see if the list contains a node with the value passed in to add.</p>
  
  <p>My issue is, I am creating the ListNode *head in the struct, then I try to access it in the LinkedList constructor to set it to null, it is throwing me the error of "undeclared identifier". even if I set it to NULL in the struct it gives me the same error. The error goes away if I write "ListNode *head = NULL" in the constructor, but then my add method is still going crazy over the use of the "undeclared identifier" head.
  Here's what I got so far:</p>
  
  <p>LinkedList.h:</p>
  
  <pre><code>class LinkedList
  {
  protected:
      struct ListNode
      {
          double value;
          ListNode *next;
          ListNode(double value1, ListNode *next1 = NULL)
          {
              value = value1;
              next = next1;
          }
          ListNode *head;
      };
      // Public Interface
  public:
      // Class Constructor(s)
      LinkedList();
  
      // Methods
      void add(double x);
      bool isMember(double x);
  
      // Private Class Members
  private:
  };
  </code></pre>
  
  <p>LinkedList.cpp:</p>
  
  <pre><code>#include "stdafx.h"
  #include "LinkedList.h"  // Class Definition file
  
  // Class Default Constructor
  LinkedList::LinkedList()
  {
      head = NULL;
  }
  
  // Class Destructor
  LinkedList::~LinkedList(void)
  {
      ListNode *nodePtr;
      while (nodePtr != NULL)
      {
          ListNode *garbage = nodePtr;
          nodePtr = nodePtr-&gt;next;
          delete garbage;
      }
  }
  
  void LinkedList::add(double x)
  {
      ListNode *nodePtr, *prevNodePtr;
      if (head == NULL || head-&gt;value &gt;= x)
      {
          head = new ListNode(x, head);
      }
      else
      {
          nodePtr = head-&gt;next;
  
          while (nodePtr != NULL &amp;&amp; nodePtr-&gt;value &lt; x)
          {
              prevNodePtr = nodePtr;
              nodePtr = nodePtr-&gt;next;
          }
  
          prevNodePtr-&gt;next = new ListNode(x, nodePtr);
      }
  }
  bool LinkedList::isMember(double x)
  {
          //tbd
  }
  </code></pre>
  
  <p>Any clues as to why this is would be a huge help. Thanks!</p>