类的静态类型处理,可以避免全局变量使用.......请看如下代码:
 
 
 
 
#include "stdafx.h"
#include
 
using namespace std;
 
class STATIC_A{
 
public:
STATIC_A ();                 //构造函数
~STATIC_A (){};             //析构函数
void plus(){
c=c+100;
};
void print();
public:
int a;
float b;
 static int c;
 
};
int STATIC_A::c=100;
void STATIC_A::print(){
cout<<"a="<<a<<"\n"<<"b="<<b<<"\n"<<"c="<<c<<endl;
};
STATIC_A::STATIC_A (){
a=1;
b=10*a;
};
int _tmain(int argc, _TCHAR* argv[])
{
const int t=6;
STATIC_A A[t];
for (int i=0;i
A[i].plus();
A[i].print();
}
while (1);
return 0;
}

 

相关文章:

  • 2021-06-14
  • 2021-06-01
  • 2021-06-22
  • 2021-10-19
  • 2022-01-11
  • 2022-12-23
猜你喜欢
  • 2021-12-12
  • 2021-11-24
  • 2021-07-26
  • 2021-10-02
  • 2021-09-27
相关资源
相似解决方案