回答編集履歴
1
追記
answer
CHANGED
@@ -5,4 +5,35 @@
|
|
5
5
|
|
6
6
|
参考
|
7
7
|
- C++で構造体やクラスをソートする方法まとめ
|
8
|
-
[https://qiita.com/arcslab123/items/7cd217cc5fafef700dff](https://qiita.com/arcslab123/items/7cd217cc5fafef700dff)
|
8
|
+
[https://qiita.com/arcslab123/items/7cd217cc5fafef700dff](https://qiita.com/arcslab123/items/7cd217cc5fafef700dff)
|
9
|
+
|
10
|
+
追記:
|
11
|
+
偶数/奇数判定関数を作成し、それを関数の渡すような例を作成してみました。
|
12
|
+
g.cpp
|
13
|
+
```g++
|
14
|
+
#include <iostream>
|
15
|
+
|
16
|
+
typedef bool (FUNC)(int);
|
17
|
+
|
18
|
+
bool is_even(int x) {
|
19
|
+
return x % 2;
|
20
|
+
}
|
21
|
+
|
22
|
+
bool is_odd(int x) {
|
23
|
+
return (x + 1) % 2;
|
24
|
+
}
|
25
|
+
|
26
|
+
void yn(FUNC func, const int x, std::string s_ok, std::string s_ng) {
|
27
|
+
std::string ret = func(x) ? s_ok : s_ng;
|
28
|
+
std::cout << ret << "\n";
|
29
|
+
}
|
30
|
+
|
31
|
+
int main() {
|
32
|
+
yn(is_even, 1, "yes", "no");
|
33
|
+
yn(is_odd, 1, "yes", "no");
|
34
|
+
return 0;
|
35
|
+
}
|
36
|
+
```
|
37
|
+
|
38
|
+
実行例:
|
39
|
+

|