KKsan KKsan - 1 year ago 80
C++ Question

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

Hi in a cpp class X I have a

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

Where some_struct is defined as:

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

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 Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download