Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Student
- {
- private:
- int age;
- char *name;
- public:
- static int count;
- Student(int m,char *n);
- Student()
- {
- count++;
- age = 0;
- name = new char[strlen("NoName")+1];
- strcpy(name,"NoName");
- }
- ~Student()
- {
- count--;
- delete[] name;
- }
- void Print() const
- {
- cout << count << endl;
- cout << "Name=" << name <<" Age=" << age <<endl;
- }
- };
- int Student::count = 0;
- Student::Student(int m,char *n)
- {
- count++;
- age = m;
- name = new char[strlen(n) + 1];
- strcpy(name,n);
- }
- int main()
- {
- cout << "count="<<Student::count<<endl;
- Student s1, *p = new Student(23,"ZhangHong");
- s1.Print();
- p->Print();
- delete p;
- s1.Print();
- Student Stu[4];
- cout <<"count="<<Student::count<< endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement