我在 g++ 中遇到了类似的问题。我以标准方式解决了问题,但我知道可能的函数签名。我所做的,我为可能的函数指针创建了一些模板特化。
#include <cxxabi.h>
#include <iostream>
using std::cout;
using std::endl;
...
#define O cout << __PRETTY_FUNCTION__ << endl;
// Return the user-readable type name
//#if defined(__GNUC__) || defined(__GNUG__)
#define _TYPENAME(x) typeid(x).name()
#define TYPENAME(x) abi::__cxa_demangle(_TYPENAME(x), 0, 0, 0)
// Show type information for variables and type names as well
#define OTYP(x) cout << "(" << #x << ") <" << TYPENAME(x) << "> '" << _TYPENAME(x) << "'" << endl;
#define OVAL(x) cout << #x << " = " << x << ", <" << TYPENAME(x) << "> '" << _TYPENAME(x) << "'" << endl;
template <class T> void typ(T o()) { O; cout << "f "; OTYP(T); }
template <class T, class U> void typ(T o(U)) { O; cout << "F "; OTYP(T); OTYP(U); }
template <class T> void typ(T o(...)) { O; cout << "e "; OTYP(T); }
const char* testcs(const std::string& s) { return s.c_str(); }
void testv(const std::string& s) { }
void testvv() {}
void testvV(void) {}
void teste(...) { }
int main() {
typ(testcs);
typ(testv);
typ(testvv);
typ(testvV);
typ(teste);
}
输出:
void typ(T (*)(U)) [with T = const char*, U = const std::string&]
F (T) <char const*> 'PKc'
(U) <std::string> 'Ss'
void typ(T (*)(U)) [with T = void, U = const std::string&]
F (T) <void> 'v'
(U) <std::string> 'Ss'
void typ(T (*)()) [with T = void]
f (T) <void> 'v'
void typ(T (*)()) [with T = void]
f (T) <void> 'v'
void typ(T (*)(...)) [with T = void]
e (T) <void> 'v'
我希望我能帮助...