• [^] # Re: Je tiendrai jusqu'à demain

    Posté par . En réponse au journal Mono pour Android en version 1.0. Évalué à 3.

    #include <boost/function.hpp>
    #include <boost/bind.hpp>
    #include <iostream>
    typedef boost::function<int(int,int)> OperationDelegate;
    struct Console {
     void Print(OperationDelegate del) {
     int res = del(42,3); // appel safe pasque gnagnagna
     std::cout << res << std::endl;
     }
    };
    class Exemple {
     int i;
    public:
     Exemple() : i(42) {}
     int add(int a, int b) { return a + b + i; }
     int add3(int a, int LOL, int b) { return (a + b + i)*LOL; }
     void Test() {
     Console c;
     c.Print(boost::bind(&Exemple::add, this, _1, _2));
     c.Print(boost::bind(&Exemple::add3, this, _1, 1 /* valeur de LOL */, _2));
     // variante inline pour c++11
     c.Print([](int x, int y) { return x + y; });
     }
    };
    

    Oui, et ensuite ?