I want to delete properly all the elements of my vector. I need to fill a vector of vector of structs in the way you should see below, creating each time a new vector of struct invoking new
method.
this is my code:
struct node
{
int index;
double value;
}
struct problem
{
int l;
struct node **x;
};
struct problem prob; // set by read_problem
std::vector<node *> vettProbX;
int main(){
node tmpValue;
std::vector <node> *temp;
for (int i=0; i<10; i++)
{
temp = new std::vector<node>;
for (int i=0; i<10; i++)
{
tmpValue.index=i;
tmpValue.value=i;
temp->push_back(tmpValue);
}
vettProbX.push_back(temp->data());
}
prob.x=&vettProbX[0];
//Destructor
for(int CC=0; CC<vettProbX.size(); CC++)
{
delete temp[CC];
}
return 0;
}
I want to delete all the new objects allocated with NEW, but i don't know how to do it correctly.