回答編集履歴
1
コメントを受けて修正
answer
CHANGED
@@ -1,22 +1,25 @@
|
|
1
1
|
こんにちは。
|
2
2
|
|
3
|
-
|
3
|
+
コメントを見て修正しました。
|
4
4
|
|
5
|
+
単純に`template<class tFunc> tFunc* get() { return &function_name; }`で出来ます。
|
6
|
+
(function_nameに返却したい関数を記述して下さい。)
|
7
|
+
|
5
8
|
```C++
|
6
9
|
#include <iostream>
|
7
10
|
|
8
|
-
template<class tFunc>
|
9
|
-
using FuncPointer=tFunc*;
|
10
|
-
|
11
11
|
int foo(int a, short b)
|
12
12
|
{
|
13
13
|
std::cout << "foo(" << a << ", " << b << ")=" << a+b << "\n";
|
14
14
|
return a+b;
|
15
15
|
}
|
16
16
|
|
17
|
+
template<class tFunc>
|
18
|
+
tFunc* get() { return &foo; }
|
19
|
+
|
17
20
|
int main(int argc, char* argv[])
|
18
21
|
{
|
19
|
-
|
22
|
+
auto f=get<int(int, short)>();
|
20
23
|
f(10, 5);
|
21
24
|
|
22
25
|
return 0;
|