-
Notifications
You must be signed in to change notification settings - Fork 0
/
bind_test1.cpp
54 lines (44 loc) · 876 Bytes
/
bind_test1.cpp
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
#include <iostream>
#include <tr1/functional>
using namespace std;
typedef std::tr1::function<void(int)> HandlerEvent;
struct Shape
{
HandlerEvent event;
};
class Rectangle
{
private:
string m_name;
Shape m_shape;
public:
void init()
{
m_shape.event = bind(&Rectangle::onEvent, this, tr1::placeholders::_1);
}
const Shape getShape() const
{
return m_shape;
}
virtual void onEvent(int arg)
{
cout << "Rectangle::onEvent arg : " << arg << endl;
}
};
class Square : public Rectangle
{
void onEvent(int arg)
{
cout << "Square::onEvent arg : " << arg << endl;
}
};
int main()
{
Rectangle rect;
rect.init();
rect.getShape().event(333);
Square squ;
squ.init();
squ.getShape().event(444);
return 0;
}