Consider the below code :
#include <iostream>
void test_function(const char* caller_name = __FUNCTION__) {
std::cout << caller_name << " ";
}
void func1() {
test_function();
}
int main() {
test_function();
func1();
}
The above code prints nothing. Is there any way that test_function prints the name of the function from which it is called ?
Eg : For this case, output should be : main func1
I understand that desired output can be achieved if we make the argument to test_function, non default, and pass __FUNCTION__ from the caller function.
This could be achieved by using macro also, but it is not what I am looking for.
Aucun commentaire:
Enregistrer un commentaire