In my C++ code I want to be able to switch between using using arrays and variables, i.e. switch between array[2]
and two variables array_0, array_1
. However, there are a lot of occurrences of array[2]
and I was looking for a way to quick switch between the two. I was trying to use a preprocessor #define
statement.
#define array[2] array_0, array_1
int array[2]; //if define is included should become int array_0, array_1;
However, this gives the following warnings/errors.
line(1): warning: missing whitespace after the macro name
line(2): error: expected unqualified-id before ‘[’ token
From what I've seen, the problem is the square brackets. Is there anyway of making this work and have array[2]
replaced with array_0, array_1
?
This is not possible. What follows #define
must be an identifier, and array[2]
is not one.