Ignoring the aliasing violation, which itself makes your code illegal, what you're doing is equivalent to this:
typedef void(T1::* fptr)( );
fptr a;
memcpy(&a, _value, sizeof(int));
(pThis->*a)( );
It should be obvious why this is non-portable; there is no guarantee that fptr
has the same size as int
, so you are likely to either partially initialise its storage or overflow it.
This would be legal if you replace sizeof(int)
with sizeof(fptr)
, and ensure that the storage that _value
points to is large enough to contain a fptr
. However, you should still use memcpy
instead of aliasing; memcpy
is guaranteed to work (3.9p2) while aliasing can result in hard-to-detect bugs that typically show up or change behaviour under optimisation.