title: Node traversal giving Access Violation Writing Error when accessing pointer
body: <p>This has been discussed multiple times on here and other parts of the net, and should be a trivial problem to solve. However, hours of debugging later, I haven't managed to solve it. Note that this is for a C++ assignment, which I'm new to.</p>
  
  <p>I'm trying to store a WordData object tempData inside tempNode as shown in the code below:</p>
  
  <pre><code>void WordList::addNodeToEnd(WordData tempData,int currentLine, wordNode* endNode){
      if (headNode == NULL) {
          cout &lt;&lt; "**Initializing WordList Nodes**" &lt;&lt; endl;
          tempNode-&gt;wordData = tempData;
          tempNode-&gt;nextNode = NULL;
          headNode = tempNode;
          endNode = tempNode;
      }
      else {
          endNode = new wordNode{ tempData };
          endNode = NULL;
          tempNode-&gt;nextNode = endNode;
          //std::cout &lt;&lt; "current end node: " &lt;&lt; endNode-&gt;wordData.getWord() &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>The problem is this line:</p>
  
  <pre><code>tempNode-&gt;nextNode = NULL;
  </code></pre>
  
  <p>This is what tempNode is showing in VS:</p>
  
  <p><img src="https://i.stack.imgur.com/yXjyH.png" alt="what tempNode is showing"></p>
  
  <p>The error message:</p>
  
  <p><img src="https://i.stack.imgur.com/7Sj8I.png" alt="enter image description here"></p>
  
  <p>WordList class definition:</p>
  
  <pre><code>class WordList {
  private:
      std::string fileName;
  
      struct wordNode {
          WordData wordData;
          wordNode* nextNode = NULL;
  
          wordNode(WordData data) {
              //nextNode = node;
              wordData = data;
  
          }
          wordNode(){
  
          }
  
      };
  
      wordNode* headNode = NULL;
      wordNode* endNode = NULL;
      wordNode* tempNode = NULL;
      //wordNode tempNode;
  
  public:
  
      // WordList public methods:
      WordList(std::string);
  
      void parseFile();
      void addNodeToEnd(WordData tempWordData,int currentLine,wordNode* endNode);
      bool addExistingWord(std::string word,int currentLine,wordNode* traverse);
  };
  </code></pre>
  
  <p>As the error seems to be an access error, at first glance I would have thought this could be an issue. However, in other parts of my code I've used pointers and variables in class functions that were declared in the class instantiation. Also, I tried a few different variations and I can't seem to get tempNode to pickup wordData.</p>
  
  <p>full source in case someone has time on their hands and really wants to dig through:
  <a href="https://bitbucket.org/SpaceSteak/assignment-1/src" rel="nofollow noreferrer">https://bitbucket.org/SpaceSteak/assignment-1/src</a>
  it compiles on VS and Xcode.</p>