Function name built from macro using given string and argument
I am currently having a problem defining a macro in C ++.
I want like this:
#define MY_MACRO (Name, Address) __int32 Get_Name() { return Address; }
Now when I call it like this:
MY_MACRO(Test, 0x10);
he spits out
__int32 Get_Name() { return 0x10; }
^^^^
instead
__int32 Get_Test() { return 0x10; }
^^^^
How can I solve this problem? I really need Get_
in the name and then the name passed by the argument.
+3
hresult
source
to share
2 answers
Use the macro concatenation operator .
#define MY_MACRO (Name, Address) __int32 Get_##Name() { return Address; }
+6
Qix
source
to share
You have to concatenate strings this way
#define MY_MACRO(Name, Address) __int32 Get_##Name() { return Address; }
+3
4pie0
source
to share