Is it ever possible to get the current (member) function name in C++?

前端 未结 4 1029
深忆病人
深忆病人 2020-12-21 04:13

I don’t know much about RTTI, but I believe that thanks to that you can retrieve the name of variables at run-time. Is it possible to retrieve the name of the function the

相关标签:
4条回答
  • 2020-12-21 05:01

    C++11 standardized __func__ for the current function.

    Various compilers support variations of __FUNCTION__, __PRETTY_FUNCTION__, and others.

    0 讨论(0)
  • 2020-12-21 05:04

    No, it is not possible. C++ does not support reflection (neither static nor dynamic) (like e.g. C#). You would need some preprocessor magic to emulate that.

    Apart from that, there is not necessarily a notion of a function/method name during run-time (this only available as debugging information if you compiled your sources with the corresponding flags).

    0 讨论(0)
  • 2020-12-21 05:11

    No.

    C++'s run-time type identification allows you to figure out the type of an object, but not the name of the method you're currently in.

    0 讨论(0)
  • 2020-12-21 05:13

    If you're doing GNU compatible stuffs, you may want to try backtrace.

    0 讨论(0)
提交回复
热议问题