I'm wondering is there any predefined macro or something in C++ that could possible to trace back where the destructor is triggered?
It could be something like this:
class myClass{
myClass();
~myClass();
};
myClass::~myClass(){
printf("Object destroyed in %s.\n", __TRACEBACKMACRO__);
}
int main(){
myClass tempClass;
return 0;
}
It should output something like this:
Object destroyed in main().
It's better to output the scope and namespace information as well.
Additional information: FUNCTION or func macro seems only work in functions not in structs and classes. reference. Any macros that work in struct and class?