Chris
2010-04-30 01:59:01 UTC
Hi there,
A class usually has non-static member method(s). When an instance of such
class gets destroyed, is its non-static member method destroyed before its
destructor is called? The reason I raised this question is that I faced the
following problem in debug build:
I have a class which has a member data of std::map type. The map member data
has entries that are pointers to the member methods of the class, like
typedef void (MyClass::*ActionMethodType)(const char*);
std::map<string, ActionMethodType> actions;
typedef std::map<string, ActionMethodType>::iterator actionIt;
In the class destructor, actions.clear() is called. This call inside the
destructor at runtime led to an access violation inside _Orphan_ptr of
std::xtree via the std::map data member. However, calling the actions.clear()
elsewhere didn't have such access violation problem. This led me to wonder
what destruction order between member methods and destructor of a class
instance.
Regards
Chris
A class usually has non-static member method(s). When an instance of such
class gets destroyed, is its non-static member method destroyed before its
destructor is called? The reason I raised this question is that I faced the
following problem in debug build:
I have a class which has a member data of std::map type. The map member data
has entries that are pointers to the member methods of the class, like
typedef void (MyClass::*ActionMethodType)(const char*);
std::map<string, ActionMethodType> actions;
typedef std::map<string, ActionMethodType>::iterator actionIt;
In the class destructor, actions.clear() is called. This call inside the
destructor at runtime led to an access violation inside _Orphan_ptr of
std::xtree via the std::map data member. However, calling the actions.clear()
elsewhere didn't have such access violation problem. This led me to wonder
what destruction order between member methods and destructor of a class
instance.
Regards
Chris