标签:blog class code c color int
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 |
#include <boost/bind.hpp> #include <boost/function.hpp> #include <iostream> #include <algorithm> #include <vector> 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< void ( int , int )> f1 = bind(&point::setXY, &p1, _1, _2); function< void ( int , int )> f2 = bind(&point::setXY, p2, _1, _2); f1(5, 6); f2(7, 8); p1.print( ); p2.print( ); function< void (point*, int , int )> f3 = &point::setXY; function< void (point, int , int )> f4 = &point::setXY; f3(&p1, 10, 20); f4(p2, 30, 40); p1.print( ); p2.print( ); return
0; } |
结果:
1
2
3
4
5
6
7
8 |
(0,0) (0,0) (1,2) (0,0) (5,6) (0,0) (10,20) (0,0) |
boost::bind boost::function,布布扣,bubuko.com
标签:blog class code c color int
原文地址:http://www.cnblogs.com/liuzhijiang123/p/3732657.html