こういうことでしょうか?
func4 の宣言は基本的に変わっていません。
C++
1#include <iostream>
2#include <string>
3
4void f1(int a, std::string x)
5{
6 std::cout << "f1 (";
7 std::cout << "a = " << a << ", ";
8 std::cout << "x = " << x << ")\n";
9}
10
11void f2(void(*fp)(int, std::string))
12{
13 std::cout << "f2\n";
14 fp(20, "hello");
15}
16
17void func4(void(*fp)(void(*)(int a, std::string x)), int b)
18{
19 std::cout << "func4 (b = " << b << ")\n";
20 fp(f1);
21}
22
23int main() {
24 //void(*fp)(void(*)(void*)(int, string), int) = func4;
25 void (*fp)(void(*)(void(*)(int, std::string)), int) = func4;
26 fp(f2,10);
27}
実行してもあまり意味はないですが。
text
1func4 (b = 10)
2f2
3f1 (a = 20, x = hello)
以下追記
C/C++ の宣言は関数ポインターが絡むと非常にややこしくなりますね。
maisumakun さんの回答のように auto
を使って変数を定義しておき typeid
で型を表示させれば一発でわかります。
C++
1#include <iostream>
2#include <string>
3#include <typeinfo>
4
5void func4(void(*fp)(void(*)(int a, std::string x)), int b)
6{
7}
8
9int main() {
10 auto fp = func4;
11 std::cout << typeid(fp).name() << '\n';
12}
VC++ で実行すると
void (__cdecl*)(void (__cdecl*)(void (__cdecl*)(int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)),int)
std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >
は std::string
ですから、結局 void (__cdecl*)(void (__cdecl*)(void (__cdecl*)(int,std::string)),int)
となり、__cdecl
を削除すれば void (*)(void (*)(void (*)(int,std::string)),int)
となります。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/11 12:35
2019/04/11 12:41 編集