【发布时间】:2016-06-24 08:33:06
【问题描述】:
假设以下函数
std::vector<double> LocatePulseEdges(int points, double* signal_x, double* signal_y, double threshold, vector<double> left_edge, vector<double> right_edge){
cout << "1" << endl;
for (int i=0; i<points; i++){
if(signal_y[i]<threshold){// left side of the pulse
left_edge.push_back(signal_x[i]);
break;
}
if(signal_y[i]>threshold){// right side of the pulse
right_edge.push_back(signal_x[i]);
break;
}
}
cout << "6" << endl;
return left_edge;
//return right_edge;
cout << "7" << endl;
}
我在下面的代码中调用了这个函数
void Analyze(){
int points = 90000000;//hSignal->GetNbinsX();
double* x = new double[points]; // SIZE limited only by OS/Hardware
double* y = new double[points];
std::vector<double> left;
std::vector<double> right;
double threshold = 6234.34;
Function_to_Fill_X_and_Y();
LocatePulseEdges(points, x, y, threshold, left, right);
cout << "First left threshold crossing @ time : " << left[0] << endl;
}
虽然我没有收到编译错误,但当我运行程序时,它会在返回语句之前崩溃。
知道为什么会这样吗?
【问题讨论】:
-
@Boiethios :嗯......我该如何检查?如果是这种情况,我该如何解决?
-
对不起,我猜不是这样。
-
@Thanos 为什么要按值传递向量?
-
@GMichael :我还能做什么?我对指针不太熟悉...... :(
-
@Thanos 阅读参考资料...
标签: c++ function vector return