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.

208Part III: Introduction to ClassesAn entire class can be named a friend of another. This has the effect ofmaking every member function of the class a friend:class Student; // forward declarationclass Teacher{protected:int noStudents;Student *pList[100];public:void assignGrades();};class Student{friend class Teacher; // make entire class a friendpublic:// same public members as before...protected:int semesterHours; // hours earned toward graduationfloat gpa;};Now, any member function of Teacher has access to the protected membersof Student. Declaring one class a friend of the other inseparably binds thetwo classes together.

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

Saved successfully!

Ooh no, something went wrong!