title: Members of structs and pointers, C++
body: <p>I have the following snippet of code:</p>
  
  <pre><code>struct Node
  {
      Node* left;
      Node* right;
      string data;
  };    
  
  void test()
      {
          Node thing;
          thing.data = "h";
          thing.left = NULL;
          thing.right = NULL;
  
          cout&lt;&lt; "Thing data = " &lt;&lt; thing.data &lt;&lt; endl;
  
          Node* thing2;
          thing2-&gt;data = "f";
          thing2-&gt;left = NULL;
          thing2-&gt;right = NULL;
  
          cout&lt;&lt; "Thing2 data = " &lt;&lt; thing2-&gt;data &lt;&lt; endl;
  
      }
  </code></pre>
  
  <p>The problem I'm having is that thing2->data = "f" is producing a segmentation fault during runtime. I've run the program through GDB and get this error, but I can't figure out what it means:</p>
  
  <blockquote>
    <p>Reading symbols for shared libraries ++. done 
    Thing data = h</p>
    
    <p>Program received signal
    EXC_BAD_ACCESS, Could not access
    memory. Reason: 13 at address:
    0x0000000000000000 0x00007fff874d59a3
    in std::string::assign ()</p>
  </blockquote>
  
  <p>Any help would be great. Thanks!</p>