Is it possible to print the name of the function from where the print method is being called? Go through the following pseudo code.
1 2 3 4 5 6 7
void foo (void)
{
cout << XXX << endl;
// XXX is some kind of macro, like __LINE__,
// that contains the name of the current function.
// i.e. void foo (void)
}
Similarly, in the context of C++, it is possible to print the name a class with typeid (*this).name (). But what about the name of a method?
I got the answer. In general, it is __FUNCTION__. This works well both with gcc and vc2005. __func__ is not supported in vc2005.
In gcc, there is __PRETTY_FUNCTION__ which prints the entire name of the function, e.g. int Class::foo (int arg).