SlideShare a Scribd company logo
OOPC
FRIEND FUNCTION
Dhananjaysinh Jhala
SY CE-1, Batch B
170410107027
FRIEND FUNCTION
While learning C++, we have emphasized on the fact that private members
cannot be accessed from outside the class i.e. A non member function cannot
have access to the private data of a class.
However, there could arise a situation where we would like 2 classes to share
a particular function.
 In such situations, C++ allows a common function to be made friendly with
both the classes, allowing the function to have access to the private members
of these classes outside the class.
This can be seen as a real life analogy, where is a person would like to come
in your house, then you need to declare him as your friend so that I can access
your private resources.
 Syntax of the friend function is given below
 Function declared with the keyword friend is called friend
function.
Some special characteristics of friend function are as
follows:
It is not in the scope of the class to which it has been declared
as friend.
It can be invoked like a normal function without any object
needed.
Unlike Member function, it cannot access the member names
directly, and has to use object name and dot membership
operator with each member name.
It can be declared as public or private without affecting its
meaning
Usually it has object as arguments
Member functions of one class can be friend functions of another
class. In such cases, they are designed using the scope resolution
operator.
We can also declared the class as a friend class.
PROGRAM TO FIND AVERAGE USING FRIEND FUNCTION
Friend function OOPC
OUTPUT
Friend function OOPC

More Related Content

PDF
Friend function in c++
PPT
friend function(c++)
PPTX
Friend Function
PDF
Access specifiers (Public Private Protected) C++
PPTX
Friend function
PPT
Friends function and_classes
PPTX
[OOP - Lec 07] Access Specifiers
PPTX
Object as function argument , friend and static function by shahzad younas
Friend function in c++
friend function(c++)
Friend Function
Access specifiers (Public Private Protected) C++
Friend function
Friends function and_classes
[OOP - Lec 07] Access Specifiers
Object as function argument , friend and static function by shahzad younas

What's hot (19)

PPTX
Friend function & friend class
PPTX
Understanding class, object & interface
PDF
Lecture 10
PPTX
Friend functions
PPTX
Member Function in C++
PPTX
Classes and objects
PPT
Inheritance C#
PDF
Chapter23 friend-function-friend-class
PDF
Learn C# Programming - Classes & Inheritance
PPTX
Inheritance
PPTX
class c++
PPTX
Classes and objects 21 aug
DOCX
Java interface
PPTX
Inheritance, friend function, virtual function, polymorphism
PPTX
Inheritance in oops
PPTX
C# Inheritance
PPTX
Class and object
PPTX
interface in c#
PPTX
C# classes objects
Friend function & friend class
Understanding class, object & interface
Lecture 10
Friend functions
Member Function in C++
Classes and objects
Inheritance C#
Chapter23 friend-function-friend-class
Learn C# Programming - Classes & Inheritance
Inheritance
class c++
Classes and objects 21 aug
Java interface
Inheritance, friend function, virtual function, polymorphism
Inheritance in oops
C# Inheritance
Class and object
interface in c#
C# classes objects
Ad

Similar to Friend function OOPC (20)

PPTX
Study of Friend Function in C++ with examples
PPTX
424570636-friend-function-1-pptx.hiipptx
PPTX
Friend function
PPT
12-170211073924.ppthihello heoobchdhdhdhhd
PPTX
Friend_Function_in_CPP its use and examples.
PPTX
cse l 5.pptx
PPTX
2.6 Friend Function which helps to learn how the friend function works
PPTX
friend_derivedclasspresentation1234.pptx
PDF
Lec_15_OOP_ObjectsAsParametersFriendClasses.pdf
PDF
Friend Function Computer Programming.pdf
PPTX
friend class & friend function by Komal V Rokade.pptx
PPTX
L9_Friend Function.pptxyeyeyeyeyyeyeyeye
PPTX
constructor , operator overloading ,friend function
PPTX
+2 CS class and objects
PPT
DS Unit 6.ppt
PPTX
Friend function in c++
PPTX
Lecture-11 Friend Functions and inline functions.pptx
PDF
A COMPLETE FILE FOR C++
PDF
22 scheme OOPs with C++ BCS306B_module1.pdf
PPT
static member and static member fumctions.ppt
Study of Friend Function in C++ with examples
424570636-friend-function-1-pptx.hiipptx
Friend function
12-170211073924.ppthihello heoobchdhdhdhhd
Friend_Function_in_CPP its use and examples.
cse l 5.pptx
2.6 Friend Function which helps to learn how the friend function works
friend_derivedclasspresentation1234.pptx
Lec_15_OOP_ObjectsAsParametersFriendClasses.pdf
Friend Function Computer Programming.pdf
friend class & friend function by Komal V Rokade.pptx
L9_Friend Function.pptxyeyeyeyeyyeyeyeye
constructor , operator overloading ,friend function
+2 CS class and objects
DS Unit 6.ppt
Friend function in c++
Lecture-11 Friend Functions and inline functions.pptx
A COMPLETE FILE FOR C++
22 scheme OOPs with C++ BCS306B_module1.pdf
static member and static member fumctions.ppt
Ad

More from Dhananjaysinh Jhala (20)

DOCX
Food donation project report II
DOCX
Food donation project report I
PPTX
JavaScript own objects(Web Technology)
PPTX
Coding standard and coding guideline
PPTX
BCD arithmetic and 16-bit data operations
PPTX
Design of a two pass assembler
PPT
Binary search trees
PPTX
Sleeping barber problem
PPTX
Email and DNS
PPTX
applications of first order non linear partial differential equation
PPTX
concepts of national income
PPTX
Circular Queue data structure
PPTX
variable entered map digital electronics
PPTX
2 phase locking protocol DBMS
DOCX
Dark sensor using photodiode
PPTX
Parabola, hyperbola and its applications
PPTX
1st, 2nd kind improper integrals
PPTX
Corporate life and skills
PPTX
type1,2 superconductors
PPTX
Earthing, grounding and isolation
Food donation project report II
Food donation project report I
JavaScript own objects(Web Technology)
Coding standard and coding guideline
BCD arithmetic and 16-bit data operations
Design of a two pass assembler
Binary search trees
Sleeping barber problem
Email and DNS
applications of first order non linear partial differential equation
concepts of national income
Circular Queue data structure
variable entered map digital electronics
2 phase locking protocol DBMS
Dark sensor using photodiode
Parabola, hyperbola and its applications
1st, 2nd kind improper integrals
Corporate life and skills
type1,2 superconductors
Earthing, grounding and isolation

Recently uploaded (20)

PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
737-MAX_SRG.pdf student reference guides
PDF
Well-logging-methods_new................
PPT
Total quality management ppt for engineering students
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Current and future trends in Computer Vision.pptx
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PPT
Mechanical Engineering MATERIALS Selection
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PPTX
Safety Seminar civil to be ensured for safe working.
PPTX
Construction Project Organization Group 2.pptx
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
Automation-in-Manufacturing-Chapter-Introduction.pdf
737-MAX_SRG.pdf student reference guides
Well-logging-methods_new................
Total quality management ppt for engineering students
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
III.4.1.2_The_Space_Environment.p pdffdf
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
UNIT 4 Total Quality Management .pptx
Current and future trends in Computer Vision.pptx
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
Mechanical Engineering MATERIALS Selection
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
Safety Seminar civil to be ensured for safe working.
Construction Project Organization Group 2.pptx
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
R24 SURVEYING LAB MANUAL for civil enggi

Friend function OOPC

  • 1. OOPC FRIEND FUNCTION Dhananjaysinh Jhala SY CE-1, Batch B 170410107027
  • 2. FRIEND FUNCTION While learning C++, we have emphasized on the fact that private members cannot be accessed from outside the class i.e. A non member function cannot have access to the private data of a class. However, there could arise a situation where we would like 2 classes to share a particular function.  In such situations, C++ allows a common function to be made friendly with both the classes, allowing the function to have access to the private members of these classes outside the class. This can be seen as a real life analogy, where is a person would like to come in your house, then you need to declare him as your friend so that I can access your private resources.
  • 3.  Syntax of the friend function is given below  Function declared with the keyword friend is called friend function.
  • 4. Some special characteristics of friend function are as follows: It is not in the scope of the class to which it has been declared as friend. It can be invoked like a normal function without any object needed. Unlike Member function, it cannot access the member names directly, and has to use object name and dot membership operator with each member name. It can be declared as public or private without affecting its meaning Usually it has object as arguments
  • 5. Member functions of one class can be friend functions of another class. In such cases, they are designed using the scope resolution operator. We can also declared the class as a friend class.
  • 6. PROGRAM TO FIND AVERAGE USING FRIEND FUNCTION