Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<stdlib.h>
- using namespace std;
- class Student{
- private:
- static int countStd;
- char* idStr;
- int id;
- string dept;
- public:
- Student(int id, string dept);
- string getId();
- int getObjectCount();
- ~Student();
- };
- int Student::countStd = 0;
- Student::Student(int id, string dept){
- this->id = id;
- this->dept = dept;
- idStr = new char[10];
- cout<<"\ninside constructor - "<< ++countStd<<" th Object\n";
- }
- int Student::getObjectCount(){
- return countStd;
- }
- string Student::getId(){
- itoa(this->id, idStr, 10);
- return this->dept+"-" +string(idStr);
- }
- Student::~Student(){
- cout<<"\ninside destructor\n";
- countStd--;
- delete [] idStr;
- }
- int main(){
- Student student(1, "s1");
- Student *s = new Student(2,"s2");
- delete s;
- cout<<"\nCurrent number of objects available: "<< s->getObjectCount();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement