TEST.CPP混淆DEBUG宏
#include <iostream>
#include "Class1.h"
#define DEBUG
int main() {
checkAssert();
}
Class1.h
#include <cassert>
#ifndef CLASS1_H_
#define CLASS1_H_
#if defined(DEBUG)
void checkAssert(){
int number = 10;
assert(number == 10);
}
#else
void checkAssert(){
std::cout << "opps" << std::endl;
}
#endif /* DEBUG */
#endif /* CLASS1_H_ */
1.我在主文件中定義DEBUG。
2.In Class1.h #if defined(DEBUG)用於檢查DEBUG是否被定義(根據我的理解)。
我試圖通過這個程序來了解DEBUG宏如何在C++中工作,但每次我在屏幕上都有opps輸出。 任何人都可以請幫我理解發生了什麼事。已列入
它完美的作品。非常感謝你.. :) –
@RashedAzad,如果這回答你的問題(我相信它),那麼你應該標記這個答案是正確的。 – Mikkel