#include <stdio.h>
 class Trace {
 public:   
  Trace()
  {noisy = 0; }    
  void print(char* s)
  { if (noisy)
  printf("%s",s); } 
  void on()
  { noisy = 1; }    
  void off()
   { noisy = 0; }
  private: int noisy; 
  };
  C++改进版输入输出,前面两个列子使用和c语言相似。这种使用了C++的类。noisy是私有成员,当它被定义时,在类里面的关联函数已经被运算。这个函数中,只要noisy为非零数,就有输出。若输入0的话,关闭函数。
  对比
 #include <stdio.h>
 static int noisy = 1;
 void trace(char *s) 
 {    
 if(noisy) printf("%s\n",s); 
 }
 void trace_on()
 { noisy = 1; }
 void trace_off()
 { noisy = 0; }
 第二种,浪费空间,占用内存,这种方式三个函数一一运行,无法在这个例子上来更改。
 第一种 类的实现类似于通信中的系统(电路),有了基本模型,可以修改成类似作用的函数。