Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Macro expansion in C++

Tags:

c++

macros

How can I define a macro (or a workaround for this) where the parameter is at the beginning of the line?

#define SINGLETON_IMPLEMENTATION(className) \
    ##className* ##className::instance_ = NULL;

This give a compiler warning (GCC 3.2.3): " '##' cannot appear at either end of a macro expansion"

like image 398
LK. Avatar asked Dec 01 '22 12:12

LK.


1 Answers

You only need ## to append a parameter to another string. Your macro can be recast as

#define SINGLETON_IMPLEMENTATION(className) \
    className* className::instance_ = NULL;
like image 93
Jon Bright Avatar answered Dec 05 '22 06:12

Jon Bright