#include<iostream>
using namespace std;
class Student
{
static int num; //静态变量
int id;
public:
Student()
{
num++;
}
~Student()
{
num--;
}
int getid()
{
id=0;
return num;
}
static int getNum()
{
return num;
}
};
int Student::num=0; //静态变量初始化
int main()
{
Student t1;
Student t2;
Student *t3=new Student;
cout<<"student num1"<<t2.getNum()<<endl;
delete t3;
cout<<"student num2"<<t3->getNum()<<endl;
}
网友评论