KKsan KKsan - 1 month ago 11
C++ Question

std::map<struct, int> Do I need destructor ?

Hi in a cpp class X I have a

class X{
private:
std::map<some_struct, int> C;
}


Where some_struct is defined as:

typedef struct{
int a;
int b;
int c;
}some_struct;


My question is: do I need to specify anything about the map C in X's destructor?
If yes, what action should X's destructor do for map C?

Answer

No, you don't need to specify a destructor for some_struct or class X

For any types it is generated by the compiler automatically. As long there wasn't anything explicitly allocated with the class at dynamic storage with new or new [], you don't need to write a destructor that applies a delete or delete[] operation.


Also for writing c++ code (vs c) you don't need to use that typedef syntax:

struct some_struct {
    int a;
    int b;
    int c;
};