第二十五章补充内容 7 调试的级别 简单

// 第二十五章补充内容 7 调试的级别
/*#include <iostream>
#include <string>
using namespace std;
#define DEBUG 2
#if DEBUG < 2
	#define ASSERT(x)
#else
#define ASSERT(x)\
if(!(x))\
{\
	cout<<"错误!Assert("<<#x<<")宏函数执行失败"<<endl;\
	cout<<"错误代码出现在第"<<__LINE__<<"行"<<endl;\
	cout<<"错误文件在:"<<__FILE__<<endl;\
}
#endif

#if DEBUG < 3
#define SHOW(x)
#else
#define SHOW(x)\
	cout<<"x:"<<x<<endl;
#endif

#if DEBUG<4
#define PRINT(x)
#else
#define PRINT(x) \
	cout<<#x<<endl;
#endif

class Circel
{
public:
	double check()const
	{
	    SHOW("进行3级检查");
		PRINT("进行4级检查");
		return radius;
	}
	void set(double x)
	{
	    ASSERT(check());
		radius = x;
		ASSERT(check());
	}

	double Result()
	{
	    return 3.14*radius*radius;
	}
private:
	double radius;
};
int main()
{
	Circel one;
	one.set(14);
	cout<<"圆的面积为"<<one.Result()<<endl;
	one.set(0);
	cout<<"圆的面积为"<<one.Result()<<endl;
    return 0;
}*/
//注意,由于程序员之间的默认约定,宏名一定要大写,假如你不这么做,那么会令许多程序员在读你的代码时感到不适应,另外,由于宏不是函数,因此请不要在宏内进行变量的赋值或者自增操作

  

原文地址:https://www.cnblogs.com/xiangxiaodong/p/2725079.html