#include
#include
using namespace std;
class Student
{
public:
Student() {total++;}
static void DispTotal()//定义静态数据成员
{
cout<<“Students’ number is:”<<total<<endl;
//静态成员函数中只引用静态数据成员
}
private:
string name;
int score;
static int total;//定义静态数据成员
};
int Student::total=0;
int main(int argc, const char * argv[]) {
// insert code here…
//std::cout << “Hello, World!\n”;
Student s1[50];
Student::DispTotal();
return 0;
}
输出结果:
Students’ number is:50
Program ended with exit code: 0