11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

256Part III: Introduction to Classes//// CallStaticMember - demonstrate two ways to call a static// member function//#include #include #include using namespace std;class Student{public:Student(char* pN = “no name”){pName = new char[strlen(pN) + 1];if (pName){strcpy(pName, pN);}noOfStudents++;}~Student() { noOfStudents--; }static int number() { return noOfStudents; }// ...other stuff the same...protected:char* pName;static int noOfStudents;};int Student::noOfStudents = 0;int main(int argcs, char* pArgs[]){Student s1(“Chester”);Student s2(“Scooter”);cout

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!