1

I am trying to map a string to a function. The function should get a const char* passed in. I am wondering why I keep getting the error that

*no match for call to ‘(boost::_bi::bind_t<boost::_bi::unspecified, void (*)(const char*), boost::_bi::list0>) (const char*)’*

My code is below

#include <map>
#include <string>
#include <iostream>
#include <boost/bind.hpp>
#include <boost/function.hpp>



typedef boost::function<void(const char*)> fun_t;
typedef std::map<std::string, fun_t> funs_t;



void $A(const char *msg)
{
    std::cout<<"hello $A";
}

int main(int argc, char **argv)
{
   std::string p = "hello";
   funs_t f;
   f["$A"] = boost::bind($A);
   f["$A"](p.c_str());
   return 0;
}
1
  • I'd caution you against using non-standard identifiers like $A. Commented Oct 15, 2017 at 6:31

1 Answer 1

2

In your example, using boost::bind is completely superfluous. You can just assign the function itself (it will converted to a pointer to a function, and be type erased by boost::function just fine).

Since you do bind, it's not enough to just pass the function. You need to give boost::bind the argument when binding, or specify a placeholder if you want to have the bound object forward something to your function. You can see it in the error message, that's what boost::_bi::list0 is there for.

So to resolve it:

f["$A"] = boost::bind($A, _1);

Or the simpler

f["$A"] = $A;

Also, as I noted to you in the comment, I suggest you avoid identifiers which are not standard. A $ isn't a valid token in an identifier according to the C++ standard. Some implementations may support it, but not all are required to.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.