KKs*_*san 2 c++ destructor class
嗨,在一个cpp类XI有一个
class X{
private:
std::map<some_struct, int> C;
}
Run Code Online (Sandbox Code Playgroud)
其中some_struct定义为:
typedef struct{
int a;
int b;
int c;
}some_struct;
Run Code Online (Sandbox Code Playgroud)
我的问题是:我是否需要在X的析构函数中指定关于地图C的任何内容?如果是,X的析构函数应该为地图C做什么动作?
不,您不需要为some_struct
或指定析构函数class X
对于任何类型,它由编译器自动生成.只要没有在动态存储中使用new
or 显式分配类的任何内容new []
,就不需要编写应用delete
或delete[]
操作的析构函数.
另外,对于编写c ++代码(vs c),您不需要使用该typedef
语法:
struct some_struct {
int a;
int b;
int c;
};
Run Code Online (Sandbox Code Playgroud)