Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <functional>
- using namespace std;
- struct FirstClass
- {
- FirstClass(): x(0)
- {
- }
- int get_x() const
- {
- return x;
- }
- function<int ()> f1 = [this]() -> int
- {
- cout << "called member function f1..." << endl;
- ++x;
- f1 = f2;
- return 5;
- };
- private:
- function<int ()> f2 = [this]() -> int
- {
- cout << "called member function f2..." << endl;
- return x;
- };
- int x;
- };
- int main()
- {
- FirstClass m;
- m.f1();
- m.f1();
- function<int ()> f3 = []() -> int
- {
- cout << "called free function f3..." << endl;
- return 100500;
- };
- m.f1 = f3;
- m.f1();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment