segmentation fault with default constructor; vector not initialized properly
<p>When I call the default constructor Heap() in int main(), I have a feeling that I am not initializing my vector pointer properly giving me a segmentation fault. I am unsure of how to fix this issue. Below is a sample code with comments around the areas that I am having trouble (<code>segmentation faults</code> when adding elements to the <code>vector</code> using <code>push_back</code>). </p>

<pre><code>#include &lt;vector&gt;
#include &lt;iostream&gt;

struct A
{
  A(int av, int bv):a(av),b(bv){}

  int a, b;
};

struct Heap
{
  Heap() : ptr() {}

  Heap(std::vector&lt;A&gt; *p) : ptr(p) {}

  void makeHeap()
  {
    heapLoc.push_back(0);
    if(ptr-&gt;size()==1){
      return;
    }

    for(int i=1; i&lt;ptr-&gt;size(); ++i){
      heapLoc.push_back(i);
      filterUp(i);
    }
  }

  void filterUp(int idx)
  {
    int parent;
    parent = (idx-1)/2;

    while((*ptr)[heapLoc[parent]].b &gt; (*ptr)[heapLoc[idx]].b){
      std::swap(heapLoc[parent],heapLoc[idx]);
      idx=parent;
      parent=(parent-1)/2;
    }
  }

  void pushHeap(A newA)
  {
    int idx;

    ptr-&gt;push_back(newA);  //SEGMENTATION FAULT caused by this line when calling h2.pushback(a8)
    idx=ptr-&gt;size()-1;
    heapLoc.push_back(idx);
    filterUp(idx);
  }

  std::vector&lt;A&gt; *ptr;
  std::vector&lt;int&gt; heapLoc;
};


int main()
{
  A a0(2,5), a1(4,2), a2(8,4), a3(0,3), a4(2,1),a5(2,7);  
  std::vector&lt;A&gt; aArray;  
  aArray.push_back(a0);
  aArray.push_back(a1);
  aArray.push_back(a2); 
  aArray.push_back(a3);
  aArray.push_back(a4);
  aArray.push_back(a5);

  Heap h(&amp;aArray);
  h.makeHeap();

  A a8(99,1);
  h.pushHeap(a8);  //works fine

  Heap h2();
  h2.pushHeap(a8); //SEGMENTATION FAULT

  return 0;

}
</code></pre>
