首页 > 其他 > 详细

类的静态类型处理

时间:2019-10-15 11:56:56      阅读:85      评论:0      收藏:0      [点我收藏+]
类的静态类型处理,可以避免全局变量使用.......请看如下代码:
 
 
 
 
#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;
}

 

类的静态类型处理

原文:https://www.cnblogs.com/tangjunjun/p/11676669.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!