I am experimenting with preprocessor function-like macros so I am trying to write a macro that forward declares regular functions. But when I go to compile it says that line 2 has incorrect syntax.
What am I doing wrong?
#define FORWARD_DECLARE_CUSTOM_FUNCT(fName) "int" #fName "(int id, string msg, string cmd);"
FORWARD_DECLARE_CUSTOM_FUNCT("abc") // LINE 2: Should become "int abc(int id, string msg, string cmd);"
void test()
{
abc(1, "", "");
}
The problem is all of the quotation marks.
translates to (after concatenating the string literals):
Whereas,
translates to:
What you really need is simply:
Use it like this:
It’s all just text replacement. I would personally remove the semicolon in the macro and make the user put one in after each use as well, to make it more like a statement. It feels more natural to me.