views:

47

answers:

2

Hello, I'm writing logger file. I'd prefer to use macros _FUNCTION_ there. I don't like the way like:

Logger.write("Message", __FUNCTION__);

Maybe, it's possible to make something like:

void write(const string &message, string functionName = __FUNCTION__)
{
   // ...
}

If not, are there any ways to do that stuff not by hands (I mean passing function name)?

+2  A: 

Macros work just by text substitution - the preprocessor puts the macro definition in place of its name. You can't have "intelligent" macros like the one you suggest.

There is no support for what you want in standard C++.

Daniel Daranas
Okay. Thanks for the answer. Will remember this.
Ockonal
+3  A: 

You could do something like that by wrapping it all in a macro:

#define log(msg) Logger.write(msg, __FUNCTION__)

The downside is that you will need to have Logger in scope when using this macro.

Job