SlideShare a Scribd company logo
2) Friend Function
1) Object as Function Argument
3) Static Function
By Shahzad Younas
Superior University Depalpur
E-Mail: shzadyounas@gmail.com
Object as function argument , friend and static function by shahzad younas
Group Leader M.Shahzad Roll# 15
Group Member Fiaz Tabish Roll# 40
Group Member Ali Shahzad Roll# 28
1) Object as Function Argument
3) Static Function
2) Friend Function
Present by
M.Shahzad
Present by Fiaz
Tabish
Present by Ali
Shahzad
Review
Defining Member Function Outside
Class The member function of a class can also be
defined outside the class
 The resolution Operator :: is used in function
declarator if the function is defined outside the
class
Syntax:
Return_type class_name ::
function_name(Parameters)
Defining Member
Function in Class
class test
{
public:
void disp()
{
cout<<“Show”;
}
};
Defining Member
Function Outside Class
class test
{
public:
void disp();
};
void test :: disp()
{
cout<<“Show”;
}
Object as Function Argument
Object pass as parameters to
member function.
Same method as passing simple
variables.
Class test
{
Public:
Void disp(test);
}
Void test :: disp(test t)
{
……….;
……….;
}
Simple Example
#include<iostream.h>
#include<conio.h>
class time
{
private:
int h, m;
public:
void gettime()
{
cout<<"Enter Time
in Hours:" ;
cin>>h;
cout<<"Enter Time
in Mints:";
cin>>m;
}
void show()
{
cout<<"Hours is:"<<h<<endl;
cout<<"Mints is:"<<m<<endl;
}
void tshow()
{
cout<<"total Hours="<<h<<“ Minets=“;
cout<<m;
}
void sum(time,time);
};
void time::sum(time t1,time
t2)
{
m=t1.m+t2.m;
h=m/60;
m=m%60;
h=h+t1.h+t2.h;
}
void main()
{
time t,t1,t2;
t1.gettime();
t2.gettime();
t.sum(t1,t2);
t1.show();
t2.show();
t.tshow();
getch();
}
Program Continue . . . .
Who is a Friend ????????
A friend is one who has access to all
your “PRIVATE” stuff.
Friend Function
 Has access to all the private and
protected members of class
 A non member function
 Definition part should be kept outside
the class body, as it is not a member
function of the class.
class BSCS
{
Private:
int roll;
public:
void disp(void);
};
class MCS
{
Private:
int roll;
public:
void disp(void);
};
frien
d
frien
d
Void disp(void)
{
……….;
……….;
}
Rules for Friend Function
 Scope resolution :: not used
 Call as simple function as
exp: disp();
 Void disp(BSCS a, MCS b)
Objects of class
#include<conio.h>
#include<iostream.h>
class A; // Forward Decleration
class B
{
private:
int b;
public:
void getval(int x)
{
b=x;
}
void showval(void)
{
cout<<"Value of b:"<<b<<endl;
}
friend void add(A,B);
};
class A
{
private:
int a;
public:
void getval(int x)
{
a=x;
}
void showval(void)
{
cout<<"Value of A:"<<a<<endl;
}
friend void add(A,B);
};
void add (A obj1, B obj2)
{
cout<<"Addition of A and B:"<<obj1.a+obj2.b;
}
void main()
{
A a;
B b;
clrscr();
a.getval(100);
b.getval(200);
a.showval();
b.showval();
add(a,b);
getch();
}
Program Continue . . . .
Static Functions
 A type of member function that can be
accessed without any object of class
is called static Function.
Class test
{
Static void dis(void);
};
Test::dis()
Simple Example
#include<iostream.h>
#include<conio.h>
class Test
{
private:
static int n;
public:
static void show()
{
cout<<"n="<<n<<endl;
}
};
int Test :: n=10;
void main()
{
clrscr();
Test::show();
getch();
}
Object as function argument , friend and static function by shahzad younas

More Related Content

What's hot (20)

PPTX
Friend function & friend class
Abhishek Wadhwa
 
PPTX
Array of objects.pptx
RAGAVIC2
 
PPTX
Friend function
zindadili
 
PPTX
Operator overloading
Kumar
 
PPTX
Inheritance In C++ (Object Oriented Programming)
Gajendra Singh Thakur
 
PPTX
Threads in JAVA
Haldia Institute of Technology
 
PPTX
Java awt (abstract window toolkit)
Elizabeth alexander
 
PPTX
SUBQUERIES.pptx
RenugadeviR5
 
PPTX
Access specifier
zindadili
 
PDF
C++ Files and Streams
Ahmed Farag
 
PPT
Object-oriented concepts
BG Java EE Course
 
PPTX
Inline function in C++
Jenish Patel
 
PPTX
Trigger in mysql
Prof.Nilesh Magar
 
PPSX
Exception Handling
Reddhi Basu
 
PDF
Arrays in Java
Naz Abdalla
 
PPTX
INLINE FUNCTION IN C++
Vraj Patel
 
PPT
Memory allocation (4)
rockymani
 
PPT
Friends function and_classes
asadsardar
 
PPTX
Virtual base class
Tech_MX
 
Friend function & friend class
Abhishek Wadhwa
 
Array of objects.pptx
RAGAVIC2
 
Friend function
zindadili
 
Operator overloading
Kumar
 
Inheritance In C++ (Object Oriented Programming)
Gajendra Singh Thakur
 
Java awt (abstract window toolkit)
Elizabeth alexander
 
SUBQUERIES.pptx
RenugadeviR5
 
Access specifier
zindadili
 
C++ Files and Streams
Ahmed Farag
 
Object-oriented concepts
BG Java EE Course
 
Inline function in C++
Jenish Patel
 
Trigger in mysql
Prof.Nilesh Magar
 
Exception Handling
Reddhi Basu
 
Arrays in Java
Naz Abdalla
 
INLINE FUNCTION IN C++
Vraj Patel
 
Memory allocation (4)
rockymani
 
Friends function and_classes
asadsardar
 
Virtual base class
Tech_MX
 

Viewers also liked (20)

PPTX
Classes and objects
Anil Kumar
 
PPTX
Diodes
Nikhil Pandit
 
PPT
Functions in C++
Nikhil Pandit
 
PDF
Object Oriented Programming Lecture Notes
FellowBuddy.com
 
PDF
Chapter23 friend-function-friend-class
Deepak Singh
 
PPTX
Safety rules and earthing
Nikhil Pandit
 
PPT
Simplifies and normal forms - Theory of Computation
Nikhil Pandit
 
PPTX
Inline Functions and Default arguments
Nikhil Pandit
 
PPT
Software Coding- Software Coding
Nikhil Pandit
 
PPT
Arrays Basics
Nikhil Pandit
 
PPT
Friend function 6
Gaurav Choudhary
 
PPTX
Spyware and rootkit
Nikhil Pandit
 
PPTX
Inheritance, friend function, virtual function, polymorphism
Jawad Khan
 
PPT
CHAIN RULE AND IMPLICIT FUNCTION
Nikhil Pandit
 
PPTX
Friend functions
Megha Singh
 
PPTX
The scope of contribution
Nikhil Pandit
 
PPTX
4 stroke diesel engine
Nikhil Pandit
 
PPT
Use case Diagram and Sequence Diagram
Nikhil Pandit
 
PPTX
Counterfort Retaining Wall
Kaizer Dave
 
PPTX
Register transfer and micro-operation
Nikhil Pandit
 
Classes and objects
Anil Kumar
 
Functions in C++
Nikhil Pandit
 
Object Oriented Programming Lecture Notes
FellowBuddy.com
 
Chapter23 friend-function-friend-class
Deepak Singh
 
Safety rules and earthing
Nikhil Pandit
 
Simplifies and normal forms - Theory of Computation
Nikhil Pandit
 
Inline Functions and Default arguments
Nikhil Pandit
 
Software Coding- Software Coding
Nikhil Pandit
 
Arrays Basics
Nikhil Pandit
 
Friend function 6
Gaurav Choudhary
 
Spyware and rootkit
Nikhil Pandit
 
Inheritance, friend function, virtual function, polymorphism
Jawad Khan
 
CHAIN RULE AND IMPLICIT FUNCTION
Nikhil Pandit
 
Friend functions
Megha Singh
 
The scope of contribution
Nikhil Pandit
 
4 stroke diesel engine
Nikhil Pandit
 
Use case Diagram and Sequence Diagram
Nikhil Pandit
 
Counterfort Retaining Wall
Kaizer Dave
 
Register transfer and micro-operation
Nikhil Pandit
 
Ad

Similar to Object as function argument , friend and static function by shahzad younas (20)

PPT
DS Unit 6.ppt
JITTAYASHWANTHREDDY
 
PPT
static member and static member fumctions.ppt
poojitsaid2021
 
PPTX
+2 CS class and objects
khaliledapal
 
PPTX
classes & objects in cpp overview
gourav kottawar
 
PPTX
classes & objects in cpp
gourav kottawar
 
PPT
Unit vi(dsc++)
Durga Devi
 
PPTX
cse l 5.pptx
KeshavKumar395652
 
PPT
cpp class unitdfdsfasadfsdASsASass 4.ppt
nandemprasanna
 
PDF
Implementation of oop concept in c++
Swarup Boro
 
PPT
Class and object in C++
rprajat007
 
PPT
4 Classes & Objects
Praveen M Jigajinni
 
PPT
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 
PPTX
Class and object
prabhat kumar
 
PDF
Class object
Dr. Anand Bihari
 
PPTX
Data members and member functions
Marlom46
 
PPT
classes & objects.ppt
BArulmozhi
 
PPT
Classes in C++ computer language presentation.ppt
AjayLobo1
 
PDF
22 scheme OOPs with C++ BCS306B_module1.pdf
sindhus795217
 
PPTX
Operator overload rr
Dhivya Shanmugam
 
PPTX
class c++
vinay chauhan
 
DS Unit 6.ppt
JITTAYASHWANTHREDDY
 
static member and static member fumctions.ppt
poojitsaid2021
 
+2 CS class and objects
khaliledapal
 
classes & objects in cpp overview
gourav kottawar
 
classes & objects in cpp
gourav kottawar
 
Unit vi(dsc++)
Durga Devi
 
cse l 5.pptx
KeshavKumar395652
 
cpp class unitdfdsfasadfsdASsASass 4.ppt
nandemprasanna
 
Implementation of oop concept in c++
Swarup Boro
 
Class and object in C++
rprajat007
 
4 Classes & Objects
Praveen M Jigajinni
 
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 
Class and object
prabhat kumar
 
Class object
Dr. Anand Bihari
 
Data members and member functions
Marlom46
 
classes & objects.ppt
BArulmozhi
 
Classes in C++ computer language presentation.ppt
AjayLobo1
 
22 scheme OOPs with C++ BCS306B_module1.pdf
sindhus795217
 
Operator overload rr
Dhivya Shanmugam
 
class c++
vinay chauhan
 
Ad

Recently uploaded (20)

PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 

Object as function argument , friend and static function by shahzad younas

  • 1. 2) Friend Function 1) Object as Function Argument 3) Static Function By Shahzad Younas Superior University Depalpur E-Mail: [email protected]
  • 3. Group Leader M.Shahzad Roll# 15 Group Member Fiaz Tabish Roll# 40 Group Member Ali Shahzad Roll# 28
  • 4. 1) Object as Function Argument 3) Static Function 2) Friend Function Present by M.Shahzad Present by Fiaz Tabish Present by Ali Shahzad
  • 5. Review Defining Member Function Outside Class The member function of a class can also be defined outside the class  The resolution Operator :: is used in function declarator if the function is defined outside the class Syntax: Return_type class_name :: function_name(Parameters)
  • 6. Defining Member Function in Class class test { public: void disp() { cout<<“Show”; } }; Defining Member Function Outside Class class test { public: void disp(); }; void test :: disp() { cout<<“Show”; }
  • 7. Object as Function Argument Object pass as parameters to member function. Same method as passing simple variables.
  • 8. Class test { Public: Void disp(test); } Void test :: disp(test t) { ……….; ……….; } Simple Example
  • 9. #include<iostream.h> #include<conio.h> class time { private: int h, m; public: void gettime() { cout<<"Enter Time in Hours:" ; cin>>h; cout<<"Enter Time in Mints:"; cin>>m; } void show() { cout<<"Hours is:"<<h<<endl; cout<<"Mints is:"<<m<<endl; } void tshow() { cout<<"total Hours="<<h<<“ Minets=“; cout<<m; } void sum(time,time); };
  • 10. void time::sum(time t1,time t2) { m=t1.m+t2.m; h=m/60; m=m%60; h=h+t1.h+t2.h; } void main() { time t,t1,t2; t1.gettime(); t2.gettime(); t.sum(t1,t2); t1.show(); t2.show(); t.tshow(); getch(); } Program Continue . . . .
  • 11. Who is a Friend ???????? A friend is one who has access to all your “PRIVATE” stuff.
  • 12. Friend Function  Has access to all the private and protected members of class  A non member function  Definition part should be kept outside the class body, as it is not a member function of the class.
  • 13. class BSCS { Private: int roll; public: void disp(void); }; class MCS { Private: int roll; public: void disp(void); }; frien d frien d Void disp(void) { ……….; ……….; }
  • 14. Rules for Friend Function  Scope resolution :: not used  Call as simple function as exp: disp();  Void disp(BSCS a, MCS b) Objects of class
  • 15. #include<conio.h> #include<iostream.h> class A; // Forward Decleration class B { private: int b; public: void getval(int x) { b=x; } void showval(void) { cout<<"Value of b:"<<b<<endl; } friend void add(A,B); }; class A { private: int a; public: void getval(int x) { a=x; } void showval(void) { cout<<"Value of A:"<<a<<endl; } friend void add(A,B); };
  • 16. void add (A obj1, B obj2) { cout<<"Addition of A and B:"<<obj1.a+obj2.b; } void main() { A a; B b; clrscr(); a.getval(100); b.getval(200); a.showval(); b.showval(); add(a,b); getch(); } Program Continue . . . .
  • 17. Static Functions  A type of member function that can be accessed without any object of class is called static Function.
  • 18. Class test { Static void dis(void); }; Test::dis() Simple Example
  • 19. #include<iostream.h> #include<conio.h> class Test { private: static int n; public: static void show() { cout<<"n="<<n<<endl; } }; int Test :: n=10; void main() { clrscr(); Test::show(); getch(); }