[bind] Unable to pass method to simple function pointer

Hello, I am trying to make a wrapper for libxml's SAX api, for learning purpose, I am trying to use bind to wrap sax events in a class like this : namespace sax { class document { public: document(); ~document(); protected: virtual void start_node( void *user_data, const xmlChar *name, const xmlChar **attrs ); xmlSAXHandler m_evhdl; xmlParserCtxtPtr m_ctxt; }; } The start_node() function is intended to be pointed by the startElement member from xmlSAXHandler ( it has same definition than start_node ). I tried to use bind to copy function pointer in the constructor like this : document::document() { // binding here m_evhdl.startElement = boost::bind( &document::start_node, this, _1, _2, _3 ); // xml init m_ctxt = xmlCreateFileParserCtxt( "catalogue.xml" ); m_ctxt->sax = &m_evhdl; xmlParseDocument( m_ctxt ); } The issue is that I can't submit the binded function to startElement because bind submits "this" as a parameter to startElement, which is incompatible definition, so is there a solution to my binding ? Regards Carlos

AMDG Carlos wrote:
I am trying to make a wrapper for libxml's SAX api, for learning purpose, I am trying to use bind to wrap sax events in a class like this :
namespace sax { class document {
public: document(); ~document();
protected:
virtual void start_node( void *user_data, const xmlChar *name, const xmlChar **attrs );
xmlSAXHandler m_evhdl; xmlParserCtxtPtr m_ctxt; }; }
The start_node() function is intended to be pointed by the startElement member from xmlSAXHandler ( it has same definition than start_node ).
I tried to use bind to copy function pointer in the constructor like this :
document::document() {
// binding here m_evhdl.startElement = boost::bind( &document::start_node, this, _1, _2, _3 );
// xml init m_ctxt = xmlCreateFileParserCtxt( "catalogue.xml" );
m_ctxt->sax = &m_evhdl; xmlParseDocument( m_ctxt ); }
The issue is that I can't submit the binded function to startElement because bind submits "this" as a parameter to startElement, which is incompatible definition, so is there a solution to my binding ?
I don't know much about libxml, but it looks like you should
pass the this pointer in the user_data argument of start_node.
Something like this:
class document {
// ...
static void start_node_func(void* user_data, const xmlChar* name,
const xmlChar** attrs) {
static_cast
participants (2)
-
Carlos
-
Steven Watanabe