C ++,获取函数的名称 [英] C++, get the name of the function

查看:130
本文介绍了C ++,获取函数的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++中,有没有办法从这样的指针获得函数签名/名称?

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();

我想使用此数据进行日志记录。

I want to use this data for logging.

推荐答案

如果你只想记录当前的函数名,大多数编译器都有 __ FUNCTION __ 宏,

If you just want to log the current function name, most of the compilers have __FUNCTION__ macro, which will give you the current function name at compile time.

您还可以寻找堆栈行走技术(这里是 Windows示例),它可以在运行时为您提供有关当前调用堆栈和函数名称的更多信息。

You may also look for stack walking techniques (here is an example for Windows), which can provide you more information about the current call stack and function names at runtime.

这篇关于C ++,获取函数的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆