jmaton
June 21st, 2002, 04:59 PM
I am either doing this wrong or perhaps it's not possible.
I have some strings:
string m_sBlueOne;
string m_sBlueTwo;
string m_sRedOne;
string m_sRedTwo;
(etc.)
I want to create a macro to do the following:
When I call SWITCH_TO(Blue), for example , I want the following to occur:
strcpy(m_sBlueOne, "blah");
strcpy(m_sBlueTwo, "blah");
Since I intend to call SWITCH_TO(color) lots of times for different colors, I decided to be clever and write a quick macro.
#define SWITCH_TO( _color ) \
strcpy( m_s##_color##One, "blah"); \
strcpy( m_s##_color##Two, "blah");
But of course it doesn't work... My idea was that the concatenation would simply put my _color parameter into the variable name, but perhaps you can't use the ## operator to append anything but tokens? (i.e., you can't append the "One" and "Two" strings?)
Any ideas?
-J
I have some strings:
string m_sBlueOne;
string m_sBlueTwo;
string m_sRedOne;
string m_sRedTwo;
(etc.)
I want to create a macro to do the following:
When I call SWITCH_TO(Blue), for example , I want the following to occur:
strcpy(m_sBlueOne, "blah");
strcpy(m_sBlueTwo, "blah");
Since I intend to call SWITCH_TO(color) lots of times for different colors, I decided to be clever and write a quick macro.
#define SWITCH_TO( _color ) \
strcpy( m_s##_color##One, "blah"); \
strcpy( m_s##_color##Two, "blah");
But of course it doesn't work... My idea was that the concatenation would simply put my _color parameter into the variable name, but perhaps you can't use the ## operator to append anything but tokens? (i.e., you can't append the "One" and "Two" strings?)
Any ideas?
-J