简体   繁体   中英

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

Let's say I have a function:

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

And inside secondFunction()

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

I want to call whatever function called another function within that next-in-the-call-stack function without having to explicitly write the function's name. Is that possible?

C++ does not explicitly provide this feature. There are some libraries you can use to print a backtrace, but if functions are inlined, they could be elided from the list.

You'll probably need to track this yourself with some function argument.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM