我正在尝试创建一个仅在调试版本时才执行代码块的宏。我设法制作了一个仅在启用调试时才执行一行的代码,但我无法弄清楚如何执行整个代码块。
单行宏如下:
#include <iostream>
//error checking
#if defined(DEBUG) | defined(_DEBUG)
#ifndef DBG_ONLY
#define DBG_ONLY(x) (x)
#endif
#else
#ifndef DBG_ONLY
#define DBG_ONLY(x)
#endif
#endif
int main () {
DBG_ONLY(std::cout << "yar" << std::endl);
return 0;
}