How does the macro operator ## work?
For example, given a macro like this
#define REGISTER_CLASS(_class, _symname) _class::MetaClass
instance##_class(_symname);
What would REGISTER_CLASS(Sampleclass, "Sampleclass") expand to?
If you ever want to find out what the preprocessor has done, just ask the
compiler to tell you. Every compiler I know of has a command line option to
place the results of preprocessing into a file. For example, given the
following source file:
//pp.cpp:
//For example, given a macro like this
#define REGISTER_CLASS(_class, _symname)
_class::MetaClassinstance##_class(_symname);
//What would REGISTER_CLASS(Sampleclass, "Sampleclass") expand to?
int main()
{
REGISTER_CLASS(Sampleclass, "Sampleclass");
return 0;
}
the MSVC command
cl /P pp.cpp
produces a file named pp.i, containing:
#line 1 "pp.cpp"
int main()
{
Sampleclass::MetaClassinstanceSampleclass("Sampleclass");;
return 0;
}
(which may or may not reflect what you wanted the macro to actually do.)
Anyway, the ## "token pasting" operator "glues" together the preceding and
following preprocessor tokens, creating a new preprocessor token. Here's a
simple example from MSDN:
http://msdn.microsoft.com/library/d...ng/html/_predir_token.2d.pasting_operator.asp
HTH,
-leor