回答編集履歴
1
追記
test
CHANGED
@@ -13,3 +13,65 @@
|
|
13
13
|
- C++で構造体やクラスをソートする方法まとめ
|
14
14
|
|
15
15
|
[https://qiita.com/arcslab123/items/7cd217cc5fafef700dff](https://qiita.com/arcslab123/items/7cd217cc5fafef700dff)
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
追記:
|
20
|
+
|
21
|
+
偶数/奇数判定関数を作成し、それを関数の渡すような例を作成してみました。
|
22
|
+
|
23
|
+
g.cpp
|
24
|
+
|
25
|
+
```g++
|
26
|
+
|
27
|
+
#include <iostream>
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
typedef bool (FUNC)(int);
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
bool is_even(int x) {
|
36
|
+
|
37
|
+
return x % 2;
|
38
|
+
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
bool is_odd(int x) {
|
44
|
+
|
45
|
+
return (x + 1) % 2;
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
void yn(FUNC func, const int x, std::string s_ok, std::string s_ng) {
|
52
|
+
|
53
|
+
std::string ret = func(x) ? s_ok : s_ng;
|
54
|
+
|
55
|
+
std::cout << ret << "\n";
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
int main() {
|
62
|
+
|
63
|
+
yn(is_even, 1, "yes", "no");
|
64
|
+
|
65
|
+
yn(is_odd, 1, "yes", "no");
|
66
|
+
|
67
|
+
return 0;
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
```
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
実行例:
|
76
|
+
|
77
|
+
![イメージ説明](baabe5ebc3d51ce8157238756015d3a9.png)
|