我有一个有映射成员变量的类,在类析构函数中我删除了通过调用包装函数 reset() 映射成员,如下面的代码所示
void zreg::reset()
83 {
84 s_err = "";
85 bad_types = 0;
86 bad_apis = 0;
87 b_valid = false;
88
89 zt_itr_t it;
90 while ((it = m_types.begin()) != m_types.end()) {
91 delete it->second;
92 m_types.erase(it);
93 }
94
95 zf_itr_t itf;
96 while ((itf = m_apis.begin()) != m_apis.end()) {
97 delete itf->second;
98 m_apis.erase(itf);
99 }
100 }
36 zreg::~zreg()
37 {
38 reset();
39 }
class zreg
210 {
211 public:
212 // Construction/destruction
213 zreg();
214 ~zreg();
215
216 typedef std::map<std::string, z_type_info *> zt_map_t;
217 typedef std::map<std::string, z_type_info *>::iterator zt_itr_t;
218 typedef std::map<std::string, z_type_info *>::const_iterator zt_citr_t;
219 typedef std::map<std::string, z_type_function *> zf_map_t;
220 typedef std::map<std::string, z_type_function *>::iterator zf_itr_t;
221 typedef std::map<std::string, z_type_function *>::const_iterator zf_citr_t;
222
255 private:
256 size_t bad_types;
257 size_t bad_apis;
258 std::string s_err;
259 std::string s_version;
260 bool b_valid;
261
262 zt_map_t m_types;
263 zf_map_t m_apis;
上面z_type_info和z_type_function是一个类
堆栈跟踪: #0 std::map, std::allocator >, z_type_function*, std::less, std::allocator >>, std::allocator, std::allocator > const, z_type_function*>> >::~map (这=0x8006da400,__in_chrg=) 在/x/freebsd/x86_64/stdhdrs_cplus/bits/STL_map.h:94 #1 0x0000000804ea34c2 在 zreg::~zreg (this=0x805158ac0, __in_chrg=)
从 bt 可以看出,最后调用的函数是 ~zreg 析构函数,但为什么 bt 没有显示对正在调用的 reset() 函数的调用。
其次,如何重现此崩溃,因为我无法再次重现它。可能如果我把我的类 zreg 的代码拿出来,它会重现这个问题吗?
我认为崩溃发生在你 reset() 之后,在 ~map()可能是你的 zreg 实例的内存在其他地方损坏了。
我是一名优秀的程序员,十分优秀!