C++, get the name of the function

后端 未结 5 900
长发绾君心
长发绾君心 2020-12-31 03:41

In C++, is there a way to get the function signature/name from it\'s pointer like this?

void test(float data) {}
cout << typeid(&test).name();
         


        
5条回答
  •  忘掉有多难
    2020-12-31 04:22

    You cannot get the name of the function in C++, but you can print the pointer and later check the binary (if not stripped) for the function name. The signature can be printed exactly as you are doing, just that the type name is not really 'human readable'. Check your compiler documentation for what the output of your code means. In g++ the output will be PFvfE, which I don't understand completely, but identifies a pointer (P) to a function (F) returning void (v) and taking a float (f) as single argument. Don't ask me what the E is...

    (I don't have time to check the docs now, I just played with a sample program to guess that: print different function signatures)

提交回复
热议问题