0

I want to xor my instance pointer (size_t) with some sort of value from a member function pointer from it, but the compiler doesn't like

reinterpret_cast<std::size_t>(MemberFunctionPointer)

which otherwise works fine on a regular function pointer. Is there any way I can pull some sort of unique value from a member function pointer to xor with the object it's from for a hash?

I suppose this is me being ignorant about the underlying difference between a standard function pointer and a member function pointer... I will do some more research on that. However, I would still like some way to get some sort of "size_t" value from a member function pointer - or any kind of value I can turn into a size_t and use to create a unique hash value.

ThisHandleNotInUse
  • 1,135
  • 1
  • 10
  • 23
  • I suppose you need to give it as [object_instance].MemberFunctionPointer (square brackets not in your code) although the whole concept seems dubious to me. – o_weisman Nov 25 '15 at 14:17
  • That is not guaranteed by the standard to work with regular non-member function pointers either (but it does work on many common implementations). If the member function is not `static`, then I'm fairly certain that you can't achieve what you want without diving deep into how your compiler implements member functions. – eerorika Nov 25 '15 at 14:21
  • @o_weisman I don't understand... these function pointers don't point to a memory address that is set in stone like a regular pointers? Can't I get the address they're pointing at to see if two of them are pointing at the same thing? – ThisHandleNotInUse Nov 25 '15 at 14:24
  • You can achieve what you want with some template magic; you'll need an instance of the class though to achieve this .. however, could you instead test for type equality of the objects? If the objects are the same (i.e. `if (typeid(x) == typeid(some_class)) { .. }`) then the member functions are the same for the types .. ? – txtechhelp Nov 25 '15 at 15:19
  • @Simple Ugh... should have tried to cast to const... I couldn't cast member pointer to void*, and being inexperienced in C++ I didn't even think that const void* would make a difference. – ThisHandleNotInUse Nov 25 '15 at 15:37

0 Answers0