测试代码:
#include<iostream>
using namespace std;
class myclass{
int little;
public:
static int num;
myclass(){num++;}
~myclass(){num--;}
static void init(int i){num=i;}
};
int myclass::num;
void fun()
{
myclass temp;
printf("In function num is %d/n",temp.num);
}
int main()
{
myclass::init(10);
myclass a,b;
printf("in a nume is %d ; in b num is %d/n",a.num,b.num);
printf("now num in a is %d ; num in b is %d/n",a.num,b.num);
fun();
printf("now num in a is %d ; num in b is %d/n",a.num,b.num);
return 0;
}
测试结果:
in a nume is 12 ; in b num is 12
now num in a is 12 ; num in b is 12
In function num is 13
now num in a is 12 ; num in b is 12
Press any key to continue