【发布时间】:2011-09-01 19:50:25
【问题描述】:
我有一个关于 c++ 中的析构函数的问题。
我有这样的课程:
class X {
private:
string m_instanceName
string m_path;
ConnexionHashMap m_connexions;
Module** m_moduleType;
Powerdomain* m_powerDomain;
Module ** m_father;
};
以下是有关 ConnexionHashMap 的一些信息:
typedef hash_map<const string, Connexion, strptrhash, strptrequal> ConnexionHashMap;
struct Net{
string name;
vector<string> connectedPins;
bool isPin;
};
typedef struct Net Net;
struct Connexion{
string pin;
Net* net;
};
typedef struct Connexion Connexion;
如果我不想删除 m_modulType 和 m_powerDomain 和 m_father(因为它们很可能被另一个对象引用),我是否必须显式编写析构函数?
我知道 string 是一个标准对象,会被它自己的析构函数销毁,但是 ConnexionHashMap 会被标准的 hashmap 模板析构函数销毁还是我应该以某种方式手动删除它?
(在旁注中还有一种简单的方法可以查看我的程序在 Eclipse cdt 上运行时如何管理我的内存?)
【问题讨论】:
-
完全不相关的评论:在 C++ 中,您无需显式地 typedef 结构即可在没有 struct 关键字的情况下使用它。结构就像一个类(但其成员默认声明为公共)。
-
它不相关但仍然有用,感谢您的提示;)
-
CDT 有到 GDB 的控制台界面吗?如果是这样,您可以随时发出命令
x,例如x myptr或x/64xb(将64 字节显示为十六进制。)供参考sourceware.org/gdb/current/onlinedocs/gdb/…
标签: c++ eclipse-cdt