File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44// g++ test10.cpp -std=c++14 -I../common -o a.out;./a.out
55
66#include < iostream>
7+ #include < string>
78#include < vector>
89#include < algorithm>
910#include < functional>
@@ -108,23 +109,39 @@ class DemoLambda final
108109private:
109110 int x = 0 ;
110111public:
111- void print ()
112+ auto print ()
112113 {
113114 // auto f = [=]()
114- auto f = [this ]()
115+
116+ return [this ]()
115117 {
116118 cout << " member = " << x << endl;
117119 };
118120
119- f ();
120121 }
121122};
122123
123124void case5 ()
124125{
125126 DemoLambda obj;
126127
127- obj.print ();
128+ auto f = obj.print ();
129+
130+ f ();
131+ }
132+
133+ void case6 ()
134+ {
135+ auto f = [](const auto & x)
136+ {
137+ return x + x;
138+ };
139+
140+ cout << f (3 ) << endl;
141+ cout << f (0.618 ) << endl;
142+
143+ string str = " matrix" ;
144+ cout << f (str) << endl;
128145}
129146
130147int main ()
@@ -134,6 +151,7 @@ int main()
134151 case3 ();
135152 case4 ();
136153 case5 ();
154+ case6 ();
137155
138156 cout << " lambda demo" << endl;
139157}
You can’t perform that action at this time.
0 commit comments