May I use double colons in #define
? I\'d like to save some writing in the implementation files, e.g. like this:
// foo.h
#define template templ
No. The name of a macro must be an identifier; it can't consist of other characters and it can't consist of multiple tokens.
#define template
is invalid because template
is not an identifier, it is a keyword.
#define foo:: foo<T>::
was valid in C90 and C++98: it defines a macro named foo
that is replaced by :: foo<T>::
(that's not what you want to do, but it was valid). However, this is invalid in C99 and C++11 because in the newer revisions of the languages, there must be whitespace between the name of an object-like macro and its replacement list (the tokens with which it is replaced).