title: Creating a boost property tree recursively
body: <p>I am trying to create a boost property tree from a tree structure that I already have. I get a memeroy access violation error on the <code>ptree node = *p</code> line.</p>
  
  <p>How should I change this code to make it work?</p>
  
  <pre><code>ptree* WebTreeView::insertProjectNode(std::shared_ptr&lt;ITreeNode&gt; projectNode)
  {
  
  if (projectNode-&gt;Children().size() == 0)
  {
      return nullptr;
  }
  
  ptree children;
  
  for (auto child : projectNode-&gt;Children())
  {
      std::shared_ptr&lt;ITreeNode&gt; c(child); // cast raw pointer to shared pointer
      std::string nodetext = c-&gt;Name().c_str();
  
      ptree *p = insertProjectNode(c);
  
      if (p)
      {
          ptree node = *p; 
          children.put_child(nodetext, node);
      }
      else
      {
          children.put(nodetext, " ");
      }
  }
  
  return &amp;children;
  }
  </code></pre>