'how to get RTTI from member function pointers
I'm trying to add logging to some legacy code that invokes one of many member function pointers. Would like to print the name of the member function before we call it. This is just for debugging (using C++17) and it doesn't have to be portable or standard C++ (a gcc extension would be fine). Tried using typeinfo like below but it only shows the class (not the actual member function).
#include <typeinfo>
class myclass
{
public:
void foo() { }
};
int main()
{
auto x = &myclass::foo;
std::cout << typeid(x).name() << "\n";
}
There's a very clever trick on elsewhere on stack overflow where you use templates to populate an std::map with function pointers and their names (which you get from __PRETTY_FUNCTION__) but it doesn't work with member function pointers because (as far as I can tell) member function pointers can't be saved in a container.
Anyone have any ideas?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
