I am trying to mimic template behavior in C++ using macros. For instance, if I wanted a list of int*, then I would do something like this:
typedef int* IntPtr;
List_DEFINE(IntPtr)
Note that List_DEFINE(IntPtr) has no semicolon because it is a macro. I have written my list “class” (really just a couple of structs with method pointers), and tested it before making it a macro. I am now trying to “macrotize” my code, and I am running into problems. I have defined my macro like this:
#define List_DEFINE(t) \
struct List_##t_Node { \
...
In the example above, I thought that ##t would be replaced with whatever was passed into t, but that does not seem to be the case. If I define two different types of lists, I get the following error:
test.cpp:85: error: redefinition of ‘struct List_t_Node’
test.cpp:75: error: previous definition of ‘struct List_t_Node’
So in the above example, I would want struct List_IntPtr_Node to be generated, but instead List_t_Node is generated. Why?
You need