Skip to content

Commit 2691e37

Browse files
committed
test10.cpp
1 parent 4d94285 commit 2691e37

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

section2/test09.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,21 @@ catch(const exception& e)
4242
cout << e.what() << endl;
4343
}
4444

45+
void case2() noexcept
46+
{
47+
cout << "noexcept" << endl;
48+
}
49+
50+
void case3() noexcept
51+
{
52+
throw "Oh My God";
53+
}
54+
4555
int main()
4656
{
4757
case1();
58+
case2();
59+
//case3();
4860

4961
cout << "exception demo" << endl;
5062
}

section2/test10.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,38 @@
88

99
using namespace std;
1010

11+
void my_square(int x)
12+
{
13+
cout << x*x << endl;
14+
}
15+
1116
void case1()
17+
{
18+
auto pfunc = &my_square;
19+
20+
(*pfunc)(3);
21+
22+
auto func = [](int x)
23+
{
24+
cout << x*x << endl;
25+
};
26+
27+
func(3);
28+
}
29+
30+
void case2()
31+
{
32+
int n = 10;
33+
34+
auto func = [=](int x)
35+
{
36+
cout << x*n << endl;
37+
};
38+
39+
func(3);
40+
}
41+
42+
void case3()
1243
{
1344
auto f1 = [](){};
1445

@@ -43,7 +74,7 @@ class DemoLambda final
4374
}
4475
};
4576

46-
void case2()
77+
void case4()
4778
{
4879
DemoLambda obj;
4980

@@ -54,6 +85,8 @@ int main()
5485
{
5586
case1();
5687
case2();
88+
case3();
89+
case4();
5790

5891
cout << "lambda demo" << endl;
5992
}

0 commit comments

Comments
 (0)