no matching function for call to bind(unresolved overloaded function type
俺是C++新手,想玩玩C++里面的新东西,可遇到问题了,不知怎么解决,望大侠指点迷津。make报错信息为:
test.cpp: In function 'int main()':
test.cpp:20:94: error: no matching function for call to 'bind(<unresolved overloaded function type>, std::tr1::_Placeholder<1>&, double)'
mingw32-make: *** Error 1
代码:#include <tr1/functional> #include <tr1/cmath>#include <algorithm> #include <iostream> #include <vector>#include <cmath> using namespace std::tr1::placeholders; void putout (double i) { std::cout<<std::fixed << " " << i;}int main() { std::vector<double> v; v.push_back(.3); v.push_back(.8); v.push_back(.7); std::transform(v.begin(), v.end(), v.begin(), std::tr1::bind(std::tr1::comp_ellint_3, _1, .5)); std::for_each(v.begin(), v.end(), putout); return 0; } 我用的是GCC 4.5.0,tdm的 把上面代码中的std::tr1::comp_ellint_3 换成 pow ,atan2 等函数却能正常编译, std::tr1::comp_ellint_3是啥东东?
估计是它的类型不对,不匹配 3# mathe
是Complete elliptic integral of the third kind 。
tr1里面的东东。
嗯,应该是的,
感觉是不能找到合适的重载类型 _1是啥东西?好像没有定义 5# mathe
_1是bind的占位符,其全名是:std::tr1::placeholders::_1
由于用全局空间的函数atan2 ,pow 是正常的,于是我把std::tr1::comp_ellint_3函数的返回值放在一个自定义的全局函数里,就可以通过编译了:#include <tr1/functional> #include <tr1/cmath>#include <algorithm> #include <iostream> #include <vector>// #include <cmath> using std::tr1::placeholders::_1; void putout (double i) { std::cout<<std::fixed << " " << i;}double wraped (double a,double b) { return std::tr1::comp_ellint_3(a,b);}int main() { std::vector<double> v; v.push_back(.1);v.push_back(.2);v.push_back(.3);v.push_back(.4); std::transform(v.begin(), v.end(), v.begin(), std::tr1::bind(wraped, _1, .5)); std::for_each(v.begin(), v.end(), putout); return (0); } 但这种方法多了一重包装,不知道有没有直接的方法。 问题解决了,comp_elint_3函数有多个重载,必须指定一个:#include <tr1/functional> #include <tr1/cmath>#include <algorithm> #include <iostream> #include <vector> using std::tr1::placeholders::_1; void putout (double i) { std::cout<<std::fixed << " " << i;}int main() { std::vector<double> v; v.push_back(.1);v.push_back(.2);v.push_back(.3);v.push_back(.4); v.push_back(.5);v.push_back(.6);v.push_back(.7);v.push_back(.8); std::transform(v.begin(), v.end(), v.begin(), std::tr1::bind(static_cast<double (*) (double,double)>(std::tr1::comp_ellint_3), _1, .5)); std::for_each(v.begin(), v.end(), putout); return 0;} 或者将comp_elint_3 换成无重载冲突的comp_ellint_3l, comp_ellint_3f 函数 5# mathe
mathe, ,你对tr1不感兴趣吗 没用过,我不知道STL里面还有这些东东,什么时候添加进去的?
页:
[1]