Noob boost::bind member function callback question

Posted by shaz on Stack Overflow See other posts from Stack Overflow or by shaz
Published on 2010-05-25T18:31:41Z Indexed on 2010/05/25 21:01 UTC
Read the original article Hit count: 277

Filed under:
|
|
#include <boost/bind.hpp>
#include <iostream>

using namespace std;
using boost::bind;

class A {
public:
    void print(string &s) {
        cout << s.c_str() << endl;
    }
};


typedef void (*callback)();

class B {
public:
    void set_callback(callback cb) {
        m_cb = cb;
    }

    void do_callback() {
        m_cb();
    }

private:
    callback m_cb;
};

void main() {
    A a;
    B b;
    string s("message");
    b.set_callback(bind(A::print, &a, s));
    b.do_callback();

}

So what I'm trying to do is to have the print method of A stream "message" to cout when b's callback is activated. I'm getting an unexpected number of arguments error from msvc10. I'm sure this is super noob basic and I'm sorry in advance.

© Stack Overflow or respective owner

Related posts about c++

Related posts about boost