How to get function name?
-
Thanks all!
void fun()
{
string str;str = ???; //How to get the function("call") name which is call this function?
cout << str << endl; // I want output "call"
}void call()
{
fun();
}modified on Wednesday, February 25, 2009 2:19 AM
-
Thanks all!
void fun()
{
string str;str = ???; //How to get the function("call") name which is call this function?
cout << str << endl; // I want output "call"
}void call()
{
fun();
}modified on Wednesday, February 25, 2009 2:19 AM
The
__FUNCTION__
macro will give you the function name.«_Superman_» I love work. It gives me something to do between weekends.
-
The
__FUNCTION__
macro will give you the function name.«_Superman_» I love work. It gives me something to do between weekends.
I've just learned something today - and it's before 9am! I can now close my mind to further information, as I have to ration these things. Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
-
The
__FUNCTION__
macro will give you the function name.«_Superman_» I love work. It gives me something to do between weekends.
I suppose
__FUNCTION__
would expand to"foo"
while he's looking for"call"
(i.e. the caller function name). :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
I've just learned something today - and it's before 9am! I can now close my mind to further information, as I have to ration these things. Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
You can see more info about macro's(LINE,..) on the www.functionx.com and www.cplusplus.com. ;)
Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )
-
Thanks all!
void fun()
{
string str;str = ???; //How to get the function("call") name which is call this function?
cout << str << endl; // I want output "call"
}void call()
{
fun();
}modified on Wednesday, February 25, 2009 2:19 AM
-
Thanks all!
void fun()
{
string str;str = ???; //How to get the function("call") name which is call this function?
cout << str << endl; // I want output "call"
}void call()
{
fun();
}modified on Wednesday, February 25, 2009 2:19 AM
The easiest way is to require the calling function to pass in its name, which it can get with __FUNCTION__:
void fun(const char* callerName)
{
string str;str = callerName;
cout << str << endl; // I want output "call"
}void call()
{
fun(__FUNCTION__);
}Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p