https://blog.slightwind.cn/
4_4_2 静态数据成员的使用
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
class Student{
private:
int age;
string name;
public:
static int count;
Student(int m,string n){
count++;
age=m;
name=n;
}
Student(){
count++;
name="unnamed";
age=0;
}
~Student(){
count--;
}
void Print(){
cout<<"count="<<count<<endl;
cout<<name<<" "<<age<<endl;
}
};
int Student::count=0;
int main(){
cout<<"count="<<Student::count<<endl;
string stuname="ZhangHong";
Student s1,*p=new Student(23,stuname);
s1.Print();
p->Print();
delete p;
s1.Print();
Student Stu[4];
cout<<"count="<<Student::count<<endl;
return 0;
}