1

Possible Duplicate:
passing functor as function pointer

I'm trying to pass functor to function pointer, but there is a compile error. How can I use this functor?

#include <iostream>

#include <QDebug>

class MessageHandler
{
public:
    MessageHandler(int val) : m_int(val)
    {
    }

    void operator() (QtMsgType type, const char *msg)
    {
        if (type == QtDebugMsg)
            std::cout << "Debug: " << msg << " (" << m_int << ")" << std::endl;
    }

private:
    int m_int;
};

int main(int argc, char *argv[])
{
    MessageHandler handler(5);
    qInstallMsgHandler(handler);

    qDebug() << "test";

    return 0;
}

qInstallMsgHandler's parameter is a typedef for a pointer to a function with the following signature:

void myMsgHandler(QtMsgType, const char *);

Thank you.

Community
  • 1
  • 1
Brian
  • 1,663
  • 5
  • 18
  • 26

0 Answers0