欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Please use boost/bind/bind.hpp + using namespace boost::placeholders

程序员文章站 2022-05-31 21:57:47
...

The practice of declaring the Bind placeholders (_1, _2, …) in the global namespace is deprecated. Please use <boost/bind/bind.hpp> + using namespace boost::placeholders, or define BOOST_BIND_GLOBAL_PLACEHOLDERS to retain the current behavior.

  • 提示warning的代码
#include <iostream>
#include <boost/bind.hpp>

using namespace std;
using namespace boost;

int fun(int x, int y) {return x+y;}
int main() {
    int m=1, n=2;
    cout << boost::bind(fun, _1, _2)(m, n) << endl;
    return 0;
}
  • 消除warning
#include <iostream>
#include <boost/bind/bind.hpp>

using namespace std;
using namespace boost::placeholders;

int fun(int x, int y) {return x+y;}
int main() {
    int m=1, n=2;
    cout << boost::bind(fun, _1, _2)(m, n) << endl;
    return 0;
}

关注我的公众号
Please use boost/bind/bind.hpp + using namespace boost::placeholders