title: Class Self-Reference Issues
body: <p>All of my code can be found <a href="http://pastebin.com/GRrdap0b" rel="nofollow">here</a>.</p>
  
  <p>I'm trying to create a complicated tree <strong><em>for a project</em></strong> however this is just the beginning of the project (the construction of a data structure). Also, I think it would help to know that the data structure can be anything you want, and that I really want to do it this way. If you think another is better, that's grand, but I don't want to change my data structure if I don't have to, as I'd like to follow this idea through.</p>
  
  <p>That said, I'm creating a tree.</p>
  
  <p>Each node of the tree contains a string of content, bool of if it is a non-terminal (if it has children or if it is a leaf).</p>
  
  <p>Additionally, each node contains a pointer to a vector (let's call that vector v).</p>
  
  <p>V is such that it contains other vectors. Let's call one of those vectors X.</p>
  
  <p>X contains a pointer to a node.</p>
  
  <p>The code works fine except for when X contains a pointer to the node which contains V (if that makes sense). When X contains a pointer to the node which contains V, I get an infinite loop which terminates in a seg fault.</p>
  
  <p>I've been hashing this out for an hour and am pretty sure the problem is in my deconstructor, which looks like this:</p>
  
  <pre><code>Node :: ~Node () {
      for (int i = 0; i &lt; (*children).size(); i++) {
          for (int j = 0; j &lt; (*children)[i].size(); j++) {
              if ((*children)[i][j] != selfP) {
                  delete (*children)[i][j];
              }
          }
      }
  }
  </code></pre>
  
  <p>What I want to do is something like this:</p>
  
  <pre><code>for (int i = 0; i &lt; (*children).size(); i++) {
      for (int j = 0; j &lt; (*children)[i].size(); j++) {
          if ((*children)[i][j] != CURRENT_NODE_ADDRESS) {
              delete (*children)[i][j];
          }
      }
  }
  </code></pre>
  
  <p>But I can't quite figure out how to reference the address of a class I'm currently defining. Any thoughts?</p>