I have the following function in c++
void LocatePulseEdges(int points, double* signal_x, double* signal_y, double* derivative, double threshold, double* left_edge, double* right_edge){
for (int i=0; i<points; i++){
if(signal_y[i]<threshold){
left_edge.push_back(signal_x[i]);
}
}
}
When I compile it, I get the error
In function ‘void LocatePulseEdges(int, double*, double*, double*, double, double*, double*)’: error: request for member ‘push_back’ in ‘left_edge’, which is of non-class type ‘double*’
Since I am a novice in c++ and I obviously, trying to learn about pointers and how to use them, I can't understand why I can't use push_back
.
I also tried to use (*left_edge)
or (*signal_y[i])
but as expected it wasn't proper...
Any idea or help would be more than welcome!
EDIT
I modified the code as follows
void LocatePulseEdges(int points, double* signal_x, double* signal_y, double* derivative, double threshold, vector<double> left_edge, vector<double> right_edge){
for (int i=0; i<points; i++){
if(signal_y[i]<threshold){
left_edge.push_back(signal_x[i]);
}
}
}
Then in my code I call the function like this
void Analyze(unsigned int first_run, unsigned int last_run, unsigned int last_segment){
double* x = new double[points]; // SIZE limited only by OS/Hardware
double* y = new double[points];
double* derivative = new double[points];
std::vector<double> left_edge;
std::vector<double> right_edge;
Function_to_Fill_X_and_Y_and_derivative();
LocatePulseEdges(points, x, y, derivative, -0.5*RMS, left_edge, right_edge);
}
Although I get no compilation errors, the program crashes as soon as the function is called.