#include#include #include #include #include using namespace boost; using namespace std; class point {public: point(int a=0,int b=0):x(a),y(b) {} void print() { cout << "(" << x << "," << y << ")\n"; } void setX(int a) { x = a; } void setXY(int _x,int _y) { x = _x; y = _y; } private: int x,y; }; int main(int argc, char ** argv) { point p1,p2; p1.print( ); p2.print( ); bind(&point::setXY, &p1, _1, _2)(1, 2); bind(&point::setXY, p2, _1, _2)(3, 4);; p1.print( ); p2.print( ); function f1 = bind(&point::setXY, &p1, _1, _2); function f2 = bind(&point::setXY, p2, _1, _2); f1(5, 6); f2(7, 8); p1.print( ); p2.print( ); function f3 = &point::setXY; function f4 = &point::setXY; f3(&p1, 10, 20); f4(p2, 30, 40); p1.print( ); p2.print( ); return 0;}
结果:
(0,0)(0,0)(1,2)(0,0)(5,6)(0,0)(10,20)(0,0)