Posted By: tgraupmann | Apr 28th @ 4:58 PM
page 1 of 1
Comments: 8 | Views: 2138
tgraupmann
tgraupmann
tgraupmann
Is it possible to do inline string concatenation in a #define?

For example:

#define SuffixDefine(Suffix) class MySuffix { };
SuffixDefine(World)

would result in:

class MyWorld { };

???

Is it possible to combine the text "My" and "World" in the define?

Another example:

#define InlineConcat(A,B) AB

would combine A and B at compile time rather than runtime.
tgraupmann wrote:
Is it possible to do inline string concatenation in a #define?

For example:

#define SuffixDefine(Suffix) class MySuffix { };
SuffixDefine(World)

would result in:

class MyWorld { };




#define SuffixDefine(Suffix) class My##Suffix { };

Should work

Check out the Preprocessor Operators section of msdn.



Chris
Did you ever consider using templates instead of preprocessor? It's the same thing, except that you can debug it and can even do specific optimizations.
Anything is better than preprocessor use Big Smile
evildictaitor
evildictaitor
How could you use the adjective "indescribable" truthfully?
tgraupmann wrote:
A template doesn't give me the ability to dynamically modify data members and method names.

I tried a template first, but it didn't have the flexibility I wanted.


Then go for it! - The preprocessor's there to be used.

Just one point on using the preprocessor - if you don't document what you've done then in a year's time when you have to go back, you'll either spend a month working out what on earth you've done, or the poor guy who's left in charge of it will put out a hit on you with the russian mafia.