0% found this document useful (0 votes)
29 views8 pages

Friend Function

Uploaded by

dheerajaaaaa40
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views8 pages

Friend Function

Uploaded by

dheerajaaaaa40
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

MARWARI COLLEGE

RANCHI
TOPIC- FRIEND FUNCTION

PARTICIPANTS NAME :-
SHIVAM PODDAR (IT SEM 1,109)
RISHU KUMAR (IT SEM 1,174)
PRINCE KUMAR (IT SEM 1, 184)
SOUNAK KARMAKAR(IT SEM 1, 172)
ROHIT KR SAW (IT SEM 1,123)
CONTENTS
TOPICS PAGE NO
1. FRIEND FUNCTION 1
2. CHARACTERISTICS OF FRIEND FUNCTION 2
3. FRIEND CLASS 3
4. EXAMPLE OF FRIEND CLASS 4
5. PROGRAM ON FRIEND FUNCTION 5
 FRIEND FUNCTION

 A Friend function can access private and protected member of other classes in
which it is declared as friend.

Syntax :- friend return_type fun_name (class & ref)


{
// code
}
 CHARACTERISTICS OF FRIEND FUNCTION
1. It is not in the scope of class to which it has been declared as friend.
2. It cannot be called using the object.
3. It cannot be invoked like a normal function w/o object.
4. It cannot access the member names directly & has to use object name & dot
operator with each member name.
5. It can be declared either in the public or the private part of a class
w/oaffecting the meaning.
6. Usually , it has the object as arguments.
 FRIEND CLASS
 Friend class is a class that granted accessibility of private and protected member of
another class.

Syntax:- class class-name


{
private:

public:
friendclass class_name;
};
EXAMPLE OF FRIEND FUNCTION
Perfect example of friend function is ,suppose
there is a boy named Akash and we want access
in his house, but we are stranger to him, so we
can’t get access in his house.

But if we become friend to Akash, then we can get


access to Akash’s house. And that’s how a friend
function work.

In this case, Akash’s friend who is accessing


Akash’s house is friend class.
 PROGRAM ON FRIEND FUNCTION
#include<iostream> int main( )
using namespace std; {
class sample sample x;
{ x.setvalue ( );
int a; cout<<“mean value=“<<mean(x)
int b; <<“\n”;
public : return 0;
void setvalue( ) }
{
a=20;b=40;
}
friend float mean (sample S)
{
return float (s.a+s.b)/2.0;
{
Thank
you

You might also like