main.cpp
#include <iostream>
#include <string>
#include "ClassStudent.h"
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
Student a(1,'mary','m');
Student::showCount();
Student b(2,'mary','m');
Student::showCount();
return 0;
}
ClassStudent.cpp
#include "ClassStudent.h"
#include <iostream>
using namespace std;
int Student::count=0;
void Student::showCount()
{
cout<<count<<endl;
}
ClassStudent,h
#include <string>
class Student{
public:
Student(int num=0,string name='alex',char sex='m'):num(num),name(name),sex(sex){
count++;
}
static void showCount();
private:
int num;
string name;
char sex;
static int count;
};