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