Не раз наталкиваюсь на токую запись
class IObject
{
public :
IObject ( void ) {};
virtual ~IObject ( void ) {};
};
class TestCall :
public IObject
{
private :
int m_i;
float m_f;
public :
TestCall ( void ) { m_i = 999; m_f = 1.7777f; }
virtual ~TestCall ( void ) {}
public :
int __stdcall test_call_method ( int i, float f )
{
this->m_i = i;
this->m_f = f;
return m_i;
}
};
///
int main ( int, char *[] )
{
TestCall test_call;
IObject *test_call_obj = &test_call;
void *v_func = NULL;
union
{
int ( __stdcall TestCall::*cFunc ) ( int, float );
void *voidFunc;
}; cFunc = ( &TestCall::test_call_method );
v_func = voidFunc;
for ( int i = 0; i < 10000; i++ )
{
union
{
int ( __stdcall IObject::*Method )( int, float );
void *void_func;
}; void_func = v_func;
int ret = ( ( test_call_obj )->* ( Method ) ) ( i, 7.999f );
std::cout << " call method \"test_call_method\" ret = " << ret << std::endl;
}
return 0;
}
Чем грозит такое приведение типов?
union
{
int ( __stdcall IObject::*Method )( int, float );
void *void_func;
};