1 | #include <iostream> |
2 | #include <functional> |
3 | |
4 | class Item; |
5 | typedef std::function<void(int)> Action; |
6 | |
7 | class Item |
8 | {
|
9 | public:
|
10 | explicit Item(int y) : y_(y) {} |
11 | void do_action(int x) { action_(x); } |
12 | Action action_; |
13 | int y_; |
14 | };
|
15 | |
16 | int main() |
17 | {
|
18 | Item it1(3); |
19 | Action a = [&it1](int x){ std::cout << "Wert x: " << x << " Wert y: " << it1.y_ << "\n"; }; |
20 | it1.action_ = a; |
21 | it1.do_action(5); |
22 | }
|