I have a question related to setting a C++ member function as a callback function for C library's API.
I searched the boost mailing list and Google, but I could not find a clear answer.
The function I need to call is OpenSSL's CRYPTO_set_id_callback function. It accepts a function
pointer as its parameter.
The following code works fine:
unsigned long IdCallBack( )
{
return ( ( unsigned long )GetCurrentThreadId( ) );
}
CRYPTO_set_id_callback( (unsigned long (*)())IdCallBack );
I have a C++ class and I want to set the call back function to be the member function of my class, I
tried to use boost::bind:
class Test
{
public:
Test( unsigned long a ) : m_long( a )
{
}
virtual ~Test( )
{
}
unsigned long GetId()
{
return m_long;
}
void SetCallBack()
{
CRYPTO_set_id_callback( boost::bind( &Test::GetId, this ) );
}
private:
unsigned long m_long;
};
I got the following error under VC++ 7.1:
error C2664: 'CRYPTO_set_id_callback' : cannot convert parameter 1 from 'boost::_bi::bind_t