請(qǐng)各位大俠過(guò)來(lái)幫忙看一看這個(gè)代碼有什么問(wèn)題?我寫(xiě)的代碼是:#include<iostream>//#include<sstream>//#include<numeric>#include<vector>#include<algorithm>#include <functional> using namespace std;vector<string> a = { "ssd", "bbblll", "ss", "wre", "sad", "adff", "asfdsgsdg", "wetrwetgsd" };bool check_size(const string &b, string::size_type sz){return b.size() >= sz;}void main(){auto wc = std::find_if(a.begin(), a.end(), std::bind(check_size, _1, 6));}編譯環(huán)境:visual studio 2013報(bào)錯(cuò):_1是未聲明的標(biāo)識(shí)符對(duì)比MSDN中對(duì)bind函數(shù)的使用,我也并沒(méi)有語(yǔ)法錯(cuò)誤呀?是什么問(wèn)題呢#include <functional> #include <algorithm> #include <iostream> using namespace std::placeholders; void square(double x) { std::cout << x << "^2 == " << x * x << std::endl; } void product(double x, double y) { std::cout << x << "*" << y << " == " << x * y << std::endl; } int main() { double arg[] = {1, 2, 3}; std::for_each(&arg[0], arg + 3, square); std::cout << std::endl; std::for_each(&arg[0], arg + 3, std::bind(product, _1, 2)); std::cout << std::endl; std::for_each(&arg[0], arg + 3, std::bind(square, _1)); return (0); } MSDN實(shí)例代碼運(yùn)行正確
2 回答

慕婉清6462132
TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超2個(gè)贊
_1 _2 ...定義在placeholders這個(gè)namespace,所以要用 using namespace std::placeholders;
- 2 回答
- 0 關(guān)注
- 699 瀏覽
添加回答
舉報(bào)
0/150
提交
取消