c++ - Why can a Boost.Bind function be called with extra parameters? -


#include <iostream> #include <string>  #include <boost/bind.hpp>  void foo(std::string const& dummy) {     std::cout << "yo: " << dummy << std::endl; }  int main() {     int* test;     std::string bar("platypus");     (boost::bind(&foo, bar))(test, test, test, test, test, test, test, test); } 

when run, prints out, "yo: platypus." appears ignore parameters. i'd expect compile error. accidentally introduced bug code way.

i don't know why allowed, know expected behavior. here:

bind can handle functions more 2 arguments, , argument substitution mechanism more general:

bind(f, _2, _1)(x, y);                 // f(y, x) bind(g, _1, 9, _1)(x);                 // g(x, 9, x) bind(g, _3, _3, _3)(x, y, z);          // g(z, z, z) bind(g, _1, _1, _1)(x, y, z);          // g(x, x, x) 

note that, in last example, function object produced bind(g, _1, _1, _1) not contain references arguments beyond first, can still used more 1 argument. any arguments silently ignored (emphasis mine), first , second argument ignored in third example.


Comments

Popular posts from this blog

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

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -