jeudi 29 juin 2017

How to write a destructor for a class which includes a map

I have a class like:

class CPR_data{
public:
    /*some functions*/
private:
    map<int,double*> data;    //saving data
};

In the file main.cpp, I add data into the class as following:

double *data_ = new double[n_var];
auto insert_flag = data.insert(make_pair(n,data_));

I used the default destructor but it seems a Memory Leak. Do I need to delete all the arrays manually in the destructor?

Aucun commentaire:

Enregistrer un commentaire