C++11 placeholder placeholders and function bind usage

Source: Internet
Author: User

#include <iostream> #include <string> #include <functional>using namespace std;using namespace std:: placeholders;  void Test (int i, double D, const string &s) {cout << "i=" << I << "d=" << D << "s= "<< s << endl;}  int test1 (int i, double D, const string &s) {cout << "i=" << I << "d=" << D << "s=    "<< s << endl; return i;}    int main (int argc, const char *argv[]) {function<void (void) > fp;    string s = "Foo";    int a = 3;    Double b = 6.7;    fp = bind (&test, A, B, s);     FP ();    function <void (int, const string&) > FP1;    Double b2 = 4.6;    FP1 = bind (test, _1, B2, _2);     FP1 (4, "kity");    function <int (int, const string&) > FP2;    FP2 = bind<int> (Test1, _1, B2, _2);    int y = FP2 (4, "kity");     cout << y << Endl;     AUTO FN = bind (test, ten, 23.3, "Heko");//function parameter not specified, FN (); Auto FF = Bind (test, _1, _3, _2); the I parameter type in//bind corresponds to the parameter type of _j of test FF ("PPP", 12.5); Class A {public:void print (int a, double x) {cout << A << "            "<< x << Endl;    }    };    A A3;    Auto fclass= bind (&a::p rint, &AMP;A3, 11, 7.7);    Fclass (); return 0;}


Reference 39828207

C++11 placeholder placeholders and function bind usage

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.