Correct way to call boost::bind?

This is a discussion on Correct way to call boost::bind? within the C++ Programming forums, part of the General Programming Boards category; I'm trying to call boost::bind to create a function pointer to pass along to another function of mine. However, when ...

  1. #1
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532

    Correct way to call boost::bind?

    I'm trying to call boost::bind to create a function pointer to pass along to another function of mine.
    However, when I make an attempt to do so, it fails miserably.
    Here's how I'm doing it(this is the line causing the errors, if I comment it out, it compiles perfectly)
    Code:
    merc.connect_bcastCurId(boost::bind(&MusicInfo::update_currentSongTitle, this, boost::cref(merc), _1));
    I'm trying to pass along the update_currentSongTitle function in my MusicInfo class, and also pass along a constant pointer to another object of mine, as the first argument in the update_currentSongTitle function.
    Here's my prototype:
    Code:
    bool update_currentSongTitle(Merc const& merc, unsigned int const& id);
    And here's my prototype for the function that takes the function pointer:
    Code:
    void connect_bcastCurId(boost::function<bool(Merc const&, unsigned int const&)> fp);
    Here are my errors(I pastebin'ed them because they messed up the formatting if I pasted them into code tags):
    http://pastebin.com/m58247670

    Any help is appreciated, if you need more information, just ask and I'll provide it.
    Thanks.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    You already supply an argument for merc, so the resulting bind object has the signature bool (unsigned int const&) (Side note: Why pass an int by const reference? By value is better for primitives.), which of course cannot bind to a function object with the signature bool (Merc const&, unsigned int const&).

    Either change the connect_bcastCurId prototype or use another placeholder in the binder.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get RSSI value, send to sensor, sensor receive package, repackage it?
    By techissue2008 in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-04-2009, 09:13 AM
  2. Replies: 1
    Last Post: 06-10-2008, 08:38 PM
  3. my HTTP request handler code correct?
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 04-25-2008, 04:01 AM
  4. call base class function or derived class function
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 03-18-2008, 05:23 AM
  5. Call external C programs and receive data
    By ferenczi in forum C Programming
    Replies: 11
    Last Post: 02-12-2008, 11:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21