大佬教程收集整理的这篇文章主要介绍了c – tr1 :: function和tr1 :: bind,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
#include <iostream> #include <String> #include <tr1/functional> struct A { A(const std::string& n) : name_(n) {} void printit(const std::string& s) { std::cout << name_ << " says " << s << std::endl; } private: const std::string name_; }; int main() { A a("Joe"); std::tr1::function<void(const std::string&)> f = std::tr1::bind(&A::printit,&a,_1); a("Hi"); }
并得到这些错误:
我不能为我的生活找出第18行的错误.
> _1在命名空间std :: tr1 :: placeholders中定义.你需要使用Namespace std :: tr1 :: placeholders;在main()中,或使用std :: tr1 :: placeholders :: _ 1.
>第19行应为f(“Hi”),而不是(“Hi”).
#include <iostream> #include <String> #include <tr1/functional> struct A { A(const std::string& n) : name_(n) {} void printit(const std::string& s) { std::cout << name_ << " says " << s << std::endl; } private: const std::string name_; }; int main() { using namespace std::tr1::placeholders; // <------- A a("Joe"); std::tr1::function<void(const std::string&)> f = std::tr1::bind(&A::printit,_1); f("Hi"); // <--------- }
以上是大佬教程为你收集整理的c – tr1 :: function和tr1 :: bind全部内容,希望文章能够帮你解决c – tr1 :: function和tr1 :: bind所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。