C
chuan
I am trying to write a class for jackknife algorithm.
I need a dynamic array, which I call jack, inside the class.
Here is my code in jackknife.h
#include <iostream>
#include <vector>
#include <math.h>
class jackknife{
int bin;
double* jack;
double* data;
public:
jackknife();
~jackknife();
int setbin(int);
};
jackknife::jackknife() {
bin = 0;
}
jackknife::~jackknife(){
delete [] jack;
}
int jackknife::setbin(int n) {
bin = n;
jack = new double [n];
return bin;
}
I allocat memory in setbin, then debugger tells me
the program crashes in the deconstructor, when I free the memory.
I have little experience of C++, I realize the memory management must
be wrong.
But how to correct it.
Excuse me for my bad english.
I need a dynamic array, which I call jack, inside the class.
Here is my code in jackknife.h
#include <iostream>
#include <vector>
#include <math.h>
class jackknife{
int bin;
double* jack;
double* data;
public:
jackknife();
~jackknife();
int setbin(int);
};
jackknife::jackknife() {
bin = 0;
}
jackknife::~jackknife(){
delete [] jack;
}
int jackknife::setbin(int n) {
bin = n;
jack = new double [n];
return bin;
}
I allocat memory in setbin, then debugger tells me
the program crashes in the deconstructor, when I free the memory.
I have little experience of C++, I realize the memory management must
be wrong.
But how to correct it.
Excuse me for my bad english.