A more general problem with macros and templates is that macros are Stupid (tm).
The preprocessor does not care about <> or [] as grouping operators, so when analyzing a macro call:
BEGIN_MESSAGE_MAP(CGlobalEditT<TYPE,ARG_TYPE>, CDialog)
It means:
- Macro Name:
BEGIN_MESSAGE_MAP - Argument 1:
CGlobalEditT<TYPE - Argument 2:
ARG_TYPE> - Argument 3:
CDialog
He then looks at the definition of BEGIN_MESSAGE_MAP , realizes that it is a macro with two arguments and complains low.
There are two types of situations in which this can occur:
- inside a class or function
- to actually declare a template class or template function
In the latter case, you are more or less screwed up if no special macros are specified.
In the first case, you have two solutions:
- Using
typedef to provide a synonym for CGlobalEditT<TYPE,ARG_TYPE> , which does not contain a comma - Using braces around
CGlobalEditT<TYPE,ARG_TYPE> to "isolate" a comma
When brackets work, this is great, but this is not always the case.
When they do not, typedef often a suitable alternative.
In any case, this is what you need to remember about macros.
source share