C++ 通过Makro C+将行从编译中排除+;

C++ 通过Makro C+将行从编译中排除+;,c++,compilation,macros,precompile,C++,Compilation,Macros,Precompile,我有一些问题,可能很容易解决 我有这样的代码: #define _MG_ALL //This might be defined in some other headerfile #ifndef _MG_ALL #define MG_ALL <?????> #else #define MG_ALL <nothing> #endif ALL foo = thisIsSomeFunc(foo); 仅当定义了\u ALL时,才应编译此行。这也可以通过以下方法解决: #ifd

我有一些问题,可能很容易解决

我有这样的代码:

#define _MG_ALL //This might be defined in some other headerfile

#ifndef _MG_ALL
#define MG_ALL <?????>
#else
#define MG_ALL <nothing>
#endif
ALL foo = thisIsSomeFunc(foo);
仅当定义了
\u ALL
时,才应编译此行。这也可以通过以下方法解决:

#ifdef ALL
    foo = thisIsSomeFunc(int foo);
#endif

但我更喜欢同一行中的一个短宏。

您可以这样定义宏:

#ifdef _ALL
#define ALL if(1)
#else
#define ALL if(0)
#endif
当您使用它时,它将生成与此类似的代码

ALL std::cout << "Debug Message" << std::endl;
 ==> if(1) std::cout << "Debug Message" << std::endl;

ALL std::难道你就不能取消这行的注释吗
#define ALL/
@muXXmit2X我试过了,但没用。我刚读到注释剥离是在执行宏扩展之前完成的。。。