Pages

July 26, 2010

Revew OOP244 - friend & friend class

friend type helper(...);
in .h file
friend int operator==(const Student&, const Student&);
in .cpp file
int operator==(const Student& lhs, const Student& rhs) {
return lhs.no == rhs.no &&
strcmp(lhs.grade, rhs.grade) == 0;
}


Friend Classes (Optional)

A class can grant access to its own private members to all of the member functions of another class. A class friendship declaration takes the form

friend class Identifier;

where Identifier is the name of the class that is to have private access privileges.

class student{

...

public:

...

friend class Administrator;

}

No comments:

Post a Comment