title: Push elements of pointer to array to a std::list in C++
body: <p>I suppose I could just use a list however, at this point I am just curious why the following code does not work:</p>
  
  <pre><code>struct treeNode{  
      char symbol;  
      double freq;  
      int left;  
      int right;  
  };
  
  treeNode *tree;
  int nOS = 16;
  tree = (treeNode *)malloc(sizeof(treeNode) * nOS);
  list&lt;treeNode&gt; treeList;
  </code></pre>
  
  <p>After initializing all the elements in tree I try to push them to treeList and get a segmentation fault, it does not occur if tree is treeNode tree[nOS] but I am working with an unknown number of elements so I need to be able to use realloc, hence the use of malloc:</p>
  
  <pre><code>for (int i = 0; i &lt; nOS; i++) {
      treeList.push_back(tree[i]);
  }
  </code></pre>
  
  <p>I tried casting tree[i] to a various number of things: (treeNode), (const treeNode) but I can't figure out how to get it to work. Thank you!</p>