I have allocated an array of object as:
int numPlwDistanceClimb = 5;
int numFl = 6;
GRBVar** t_gd = 0;
t_gd = new GRBVar* [numFl];
GRBVar* x = 0;
x = model.addVars(numFl, GRB_CONTINUOUS);
for (int k = 0; k < numFl; k++)
{
t_gd[k] = model.addVars(numPlwDistanceClimb, GRB_CONTINUOUS);
}
I delete the arrays as follows but it does not work.
delete x;
for (int i = 0; i < numFl; ++i)
{
delete t_gd[i];
}
delete [] t_gd;
Can anyone help me? Thank you in advance
std::vectorinstead and all your problems will be handled.t_gd. If you call free on uninitialized pointers a crash is what you can expect.malloc,calloc, orrealloc? I think you're using the API incorrectly and overcomplicated your program using pointers. I am assuming that the authors of the C++ interface would properly implement the objects being returned in that there is no need for you to be manually releasing memory. TheaddVarsfunction returns an object -- why not just usestd::vector<GRBVar> t_gd(numF);and fill the vector with the return value ofaddVars?