c++ - How can boost::bind does not match the signature provided but works fine? -


my confuse code:

 #include "stdafx.h" #include <boost/bind.hpp>  using namespace std;  void fool(std::string s) {  std::cout<<s<<endl; }  void fool2() {  std::cout<<"test2 called\n"<<endl; }  void fool3(std::string s1,std::string s2) {  std::cout<<"test3 called\n"<<endl; }  typedef boost::function<void(std::string)> myhandler; void mywait(myhandler handler) {  handler("hello wait"); }  int main() {  mywait(boost::bind(fool,_1));  //it works fine expected.   mywait(boost::bind(fool2));   //how works? fool2  doesnot match  signature of  "boost::function<void(std::string)>"   //mywait(boost::bind(fool3,_1,_2)); //if fool2 works fine, why  not work?  return 0; } 

the follow link same question.

http://forums.opensuse.org/english/development/programming-scripting/441878-how-can-boost-bind-swallow-argument-member-function.html

i read article: [how boost bind library can improve c++ programs] , boost doc bind

those works,but don't know why. still confused.

sorry poor english.wish explained yet.

one of neat things boost.bind it's ability "massage" function different signature.

for example, can make fool3 example work explicitly giving value second parameter:

mywait(boost::bind(fool3, _1, "extra parameter")); // or even: mywait(boost::bind(fool3, "extra parameter", _1)); 

any parameters passed function don't used (by _n) ignored when function called.


Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -