title: C++ - Cannot return vector from function
body: <p>Assume the following function</p>
  
  <pre><code>std::vector&lt;double&gt; LocatePulseEdges(int points, double* signal_x, double* signal_y, double threshold, vector&lt;double&gt; left_edge, vector&lt;double&gt; right_edge){
  cout &lt;&lt; "1" &lt;&lt; endl;
      for (int i=0; i&lt;points; i++){
          if(signal_y[i]&lt;threshold){// left side of the pulse
              left_edge.push_back(signal_x[i]);
              break;
          }
          if(signal_y[i]&gt;threshold){// right side of the pulse
              right_edge.push_back(signal_x[i]);
              break;
          }
      }
  cout &lt;&lt; "6" &lt;&lt; endl;
      return left_edge;
      //return right_edge;
  
  cout &lt;&lt; "7" &lt;&lt; endl;
  }
  </code></pre>
  
  <p>I am calling this function in the following code</p>
  
  <pre><code>void Analyze(){
      int points = 90000000;//hSignal-&gt;GetNbinsX();
      double* x          = new double[points];           // SIZE limited only by OS/Hardware
      double* y          = new double[points];
      std::vector&lt;double&gt; left;
      std::vector&lt;double&gt; right;
      double threshold = 6234.34;
  
      Function_to_Fill_X_and_Y();
      LocatePulseEdges(points, x, y, threshold, left, right);
      cout &lt;&lt; "First left threshold crossing @ time : " &lt;&lt; left[0] &lt;&lt; endl;
  }
  </code></pre>
  
  <p>Although I get no compilation error, when I run the program, it crashes right before the return statement.</p>
  
  <p>Any idea on why this is happening?</p>