It looks like std::cout can\'t print member function\'s address, for example:
#include
using std::cout;
using std::endl;
clas
Pointers to member functions need memory, too. They also have a size. So how about printing out the memory of the pointer:
template
std::string to_string(R (T::*func)(Args...))
{
union PtrUnion
{
R(T::*f)(Args...);
std::array buf;
};
PtrUnion u;
u.f = func;
std::ostringstream os;
os << std::hex << std::setfill('0');
for (auto c : u.buf)
os << std::setw(2) << (unsigned)c;
return os.str();
}
You can use it this way:
class TestClass
{
void foo();
};
...
std::cout << to_string(&TestClass::foo) << std::endl;