Pointeur vers fonction membre
Bonjour à tous,
Aujourd'hui, je sèche sur un problème relativement simple avec boost::bind. Ca fait 1 heure que je sèche et ça m'énerve. La fatigue me direz-vous... Sans doute !
Vois un exemple de code minimal qui reproduit mon problème : je cherche à appeler un callback membre avec une signature spécifique. La classe Agent provient d'une bibliothèque tierce qui appelle une fonction ayant un prototype précis (Agent::Func ici) pour passer les infos.
Le seul truc que je peux toucher, c'est ma classe Test ! :)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#include <iostream>
#include <boost/bind.hpp>
struct foo {};
struct bar {};
void free_callback(foo*, bar*)
{}
class Agent
{
public:
typedef void (*Func)( foo*, bar* );
virtual bool Initialize ( const char* name, Agent::Func p_func = NULL ) {}
};
class Test
{
public:
Test()
{
m_agent = new Agent;
m_agent->Initialize("mon_agent", free_callback); // OK
m_agent->Initialize("mon_agent", boost::bind(&Test::CallBack, this, _1, _2) ); // KO
}
~Test()
{
delete m_agent;
}
private:
void CallBack(foo*, bar*);
Agent* m_agent;
};
int main()
{
return 0;
} |
Compilo :
Citation:
error C2664: 'Agent::Initialize'*: impossible de convertir le paramètre 2 de 'boost::_bi::bind_t<R,F,L>' en 'Agent::Func'
:koi: