是否可以访问代码中的调用堆栈?

Can I have access to the call stack in my code?

本文关键字:调用 堆栈 代码 访问 是否      更新时间:2023-10-16

假设我有一个函数:

firstFunction(){
//some code here
secondFunction();//call secondFunction
}

在里面secondFunction()

secondFunction(){
//some code here
//here call the function that called this ( in this case firstFunction() )
}

我想调用在该调用堆栈函数中的下一个函数中调用另一个函数的任何函数,而无需显式编写函数的名称。这可能吗?

C++没有明确提供此功能。有一些库可用于打印回溯,但如果函数是内联的,则可以从列表中省略它们。

您可能需要使用一些函数参数自己跟踪它。