Introduction to "friend"

A friend function of a class is defined outside that class's scope, yet has the right to access private or protected members of the class. A function or an entire class may be declared to be a friend of another class.



friend function_type function_name( .. );
e.g. friend void reset();


friend class class_name;	
e.g. friend class Time;

Sample Code

Please follow this link to see the sample code using friend.


Add a friend function equal_to to check whether counter1 is equal to counter2 of the sample code. Call this function from the main(), and display the result. Answer

BU CAS CS - Introduction to "friend"
Last Updated on: March 26, 2000
This page created by Jaehee Yoon <>.