Jos*_*vin 7 c++ boost functional-programming compiler-errors
#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);
}
在跑步时,打印出"Yo:platypus".它似乎完全忽略了额外的参数.我希望得到一个编译错误.我不小心以这种方式向我的代码中引入了一个错误.
我不知道为什么允许这样做,但我确实知道这是预期的行为。从这里:
bind 可以处理带有两个以上参数的函数,并且它的参数替换机制更加通用:
Run Code Online (Sandbox Code Playgroud)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)请注意,在最后一个示例中,bind(g, _1, _1, _1) 生成的函数对象不包含对第一个参数之外的任何参数的引用,但它仍然可以与多个参数一起使用。任何额外的参数都会被默默地忽略(强调我的),就像第三个示例中的第一个和第二个参数被忽略一样。