
Casting a method pointer to a function pointer.
I have to use a library and to call a function foo with a pointer
function in the argument
I have to pass to this function foo a method of an object.
( it's the object who call the function foo ).
I have sucess compile it with gcc under unix.
But under window's with mvsc 5 , I have problem:
So I have define two typedef :
typedef void (* BEGINTAG)(void *,const char *,const char **);^M
typedef void (* ENDTAG)(void *,const char *);^M
Corresponding of the type of the function pointer
The prototype of the method to caster is
virtual void OXMLendtag(const char *name);
virtual void OXMLbegintag(const char *name,const char **atts);^M
I have a variable who call testalacon , to try passing by a variable
instead of by a method directly.
The prototype of testalacon:
void (OXML::* testalacon)(const char *name,const char **atts);
There're two function pointer declare in the object.
BEGINTAG startfunc;^M
ENDTAG endfunc;
I set testalacon tothe pointer method:
testalacon=o->OXMLbegintag;
( no problemo ).
But MSVC 5 make me deux errors of compilation:
J:\SRC\xml\OXML.cpp(14) : error C2440: 'type cast' :
cannot convert from 'void (OXML::*)(const char *,const char ** )'
to 'void (__cdecl *)(void *,const char *,const char ** )'
For :
startfunc=(BEGINTAG)testalacon;
There is no context in which this conversion is possible
J:\SRC\xml\OXML.cpp(16) : error C2440: 'type cast' :
cannot convert from 'overloaded function type'
to 'void (__cdecl *)(void *,const char *)'
None of the functions with this name in scope match the target type
For :
endfunc=(ENDTAG)o->OXMLendtag;
How could I cast a method pointeur to a function pointer ?
( I guess it is my problem ).
Coudl somebody help me ?
Thank's a lot.
PS: Please excuse my english I'm french.
charles vidal.