Does it violate the C++ standard (any version of it) in any way to reinterpret_cast from one class method to a completely different class method pointer if neither class are derived from one another or related in any way, as long as the pointer is not dereferenced until it is reinterpret_casted back to the proper class object?
Are the types of different class method pointers different in any implementation of the standard? (For example, perhaps if one class is polymorphic and the other is not)
This post says that this usage of reinterpret_cast follows the standard: https://stackoverflow.com/a/573345
This post says that casting from method pointer to function pointer is UB, which is not what I'm doing but is similar in theory: https://stackoverflow.com/a/6908641
Edit: I need run-time generic-ness as I'm holding a vector of these pointers, and since templates are evaluated at compile-time this doesn't quite work. I kind of need to subvert the type system in order to hold a generic pointer, and to know that when I cast it back to it's original type that it will not be mangled.
Pseudo-code of what I'm trying to achieve:
// A type for Foo method pointer
typedef bool (Foo::*FOO_METHOD_PTR)( int some_arg );
// A generic method pointer type
class UnusedClass {};
typedef void (UnusedClass::*GENERIC_METHOD_PTR)( void );
// generically store a method from any class
GENERIC_METHOD_PTR generic_ptr = reinterpret_cast<GENERIC_METHOD_PTR>( &Foo::method );
// cast back to proper class
FOO_METHOD_PTR foo_ptr = reinterpret_cast<FOO_METHOD_PTR>( generic_ptr );
// macro to help call method pointers
#define CALL_METHOD(object,ptrToMethod) ((object).*(ptrToMethod))
// call
Foo foo;
CALL_METHOD(foo,foo_ptr)