title: Segmentation fault in C++ using vectors
body: <p>I'm having trouble with a segmentation fault caused by the following line:</p>
  
  <pre><code>heapVec[currentsize] = *(new Node(d));
  </code></pre>
  
  <p>What am I doing wrong here?</p>
  
  <pre><code>#include &lt;vector&gt;
  using namespace std;
  
  class Node {
  private:
      int data;
  public:
      Node(int);
      // ~Node();
  };
  
  class Heap {
  private:
      vector&lt;Node&gt; heapVec;
      int currentsize;
  public:
      Heap();
      // ~Heap();
      void insert(int);
      void extractMin();
      void reduceKey();
  };
  
  Node::Node(int d) {
      data = d;
  }
  
  void Heap::insert(int d) {
      heapVec[currentsize] = *(new Node(d));
      currentsize++;
  }
  
  Heap::Heap() {
      // this is the default constructor
      currentsize = 0;
  }
  
  int main() {
      Heap *h = new Heap;
      h-&gt;insert(10);
  }
  </code></pre>