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

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;
}

關注我的公衆號
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章