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
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

Friend function in c++
Friend function in c++ Friend function in c++
Friend function in c++
University of Madras
 
Class and object
Class and objectClass and object
Class and object
prabhat kumar
 
Classes and Objects in C#
Classes and Objects in C#Classes and Objects in C#
Classes and Objects in C#
Adeel Rasheed
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Anil Kumar
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
prabhat kumar
 
Inner classes in java
Inner classes in javaInner classes in java
Inner classes in java
PhD Research Scholar
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
Kurapati Vishwak
 
Inheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphismInheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphism
Jawad Khan
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 
Interface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementationInterface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementation
HoneyChintal
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
Abishek Purushothaman
 
[OOP - Lec 07] Access Specifiers
[OOP - Lec 07] Access Specifiers[OOP - Lec 07] Access Specifiers
[OOP - Lec 07] Access Specifiers
Muhammad Hammad Waseem
 
Inheritance
InheritanceInheritance
Inheritance
prabhat kumar
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute
 
[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing
Muhammad Hammad Waseem
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentation
tigerwarn
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
Elizabeth alexander
 
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
البرمجة الهدفية بلغة جافا - مفاهيم أساسية البرمجة الهدفية بلغة جافا - مفاهيم أساسية
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
Mahmoud Alfarra
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
Classes&amp;objects
Classes&amp;objectsClasses&amp;objects
Classes&amp;objects
M Vishnuvardhan Reddy
 

What's hot (20)

Friend function in c++
Friend function in c++ Friend function in c++
Friend function in c++
 
Class and object
Class and objectClass and object
Class and object
 
Classes and Objects in C#
Classes and Objects in C#Classes and Objects in C#
Classes and Objects in C#
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Inner classes in java
Inner classes in javaInner classes in java
Inner classes in java
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
 
Inheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphismInheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphism
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
 
Interface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementationInterface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementation
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
[OOP - Lec 07] Access Specifiers
[OOP - Lec 07] Access Specifiers[OOP - Lec 07] Access Specifiers
[OOP - Lec 07] Access Specifiers
 
Inheritance
InheritanceInheritance
Inheritance
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentation
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
 
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
البرمجة الهدفية بلغة جافا - مفاهيم أساسية البرمجة الهدفية بلغة جافا - مفاهيم أساسية
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Classes&amp;objects
Classes&amp;objectsClasses&amp;objects
Classes&amp;objects
 

Viewers also liked

Diodes
DiodesDiodes
Functions in C++
Functions in C++Functions in C++
Functions in C++
Nikhil Pandit
 
Object Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesObject Oriented Programming Lecture Notes
Object Oriented Programming Lecture Notes
FellowBuddy.com
 
Safety rules and earthing
Safety rules and earthingSafety rules and earthing
Safety rules and earthing
Nikhil Pandit
 
Simplifies and normal forms - Theory of Computation
Simplifies and normal forms - Theory of ComputationSimplifies and normal forms - Theory of Computation
Simplifies and normal forms - Theory of Computation
Nikhil Pandit
 
Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default arguments
Nikhil Pandit
 
Software Coding- Software Coding
Software Coding- Software CodingSoftware Coding- Software Coding
Software Coding- Software Coding
Nikhil Pandit
 
Arrays Basics
Arrays BasicsArrays Basics
Arrays Basics
Nikhil Pandit
 
Spyware and rootkit
Spyware and rootkitSpyware and rootkit
Spyware and rootkit
Nikhil Pandit
 
CHAIN RULE AND IMPLICIT FUNCTION
CHAIN RULE AND IMPLICIT FUNCTIONCHAIN RULE AND IMPLICIT FUNCTION
CHAIN RULE AND IMPLICIT FUNCTION
Nikhil Pandit
 
The scope of contribution
The scope of contributionThe scope of contribution
The scope of contribution
Nikhil Pandit
 
4 stroke diesel engine
4 stroke diesel engine4 stroke diesel engine
4 stroke diesel engine
Nikhil Pandit
 
Use case Diagram and Sequence Diagram
Use case Diagram and Sequence DiagramUse case Diagram and Sequence Diagram
Use case Diagram and Sequence Diagram
Nikhil Pandit
 
Counterfort Retaining Wall
Counterfort Retaining WallCounterfort Retaining Wall
Counterfort Retaining Wall
Kaizer Dave
 
Register transfer and micro-operation
Register transfer and micro-operationRegister transfer and micro-operation
Register transfer and micro-operation
Nikhil Pandit
 
Register transfer and micro operation
Register transfer and micro operationRegister transfer and micro operation
Register transfer and micro operation
Kamal Acharya
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).pptAlok Kumar
 
Object-oriented concepts
Object-oriented conceptsObject-oriented concepts
Object-oriented concepts
BG Java EE Course
 

Viewers also liked (20)

Diodes
DiodesDiodes
Diodes
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Object Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesObject Oriented Programming Lecture Notes
Object Oriented Programming Lecture Notes
 
Safety rules and earthing
Safety rules and earthingSafety rules and earthing
Safety rules and earthing
 
Simplifies and normal forms - Theory of Computation
Simplifies and normal forms - Theory of ComputationSimplifies and normal forms - Theory of Computation
Simplifies and normal forms - Theory of Computation
 
Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default arguments
 
Software Coding- Software Coding
Software Coding- Software CodingSoftware Coding- Software Coding
Software Coding- Software Coding
 
Arrays Basics
Arrays BasicsArrays Basics
Arrays Basics
 
Friend function 6
Friend function 6Friend function 6
Friend function 6
 
Spyware and rootkit
Spyware and rootkitSpyware and rootkit
Spyware and rootkit
 
CHAIN RULE AND IMPLICIT FUNCTION
CHAIN RULE AND IMPLICIT FUNCTIONCHAIN RULE AND IMPLICIT FUNCTION
CHAIN RULE AND IMPLICIT FUNCTION
 
The scope of contribution
The scope of contributionThe scope of contribution
The scope of contribution
 
4 stroke diesel engine
4 stroke diesel engine4 stroke diesel engine
4 stroke diesel engine
 
Use case Diagram and Sequence Diagram
Use case Diagram and Sequence DiagramUse case Diagram and Sequence Diagram
Use case Diagram and Sequence Diagram
 
Counterfort Retaining Wall
Counterfort Retaining WallCounterfort Retaining Wall
Counterfort Retaining Wall
 
Register transfer and micro-operation
Register transfer and micro-operationRegister transfer and micro-operation
Register transfer and micro-operation
 
Register transfer and micro operation
Register transfer and micro operationRegister transfer and micro operation
Register transfer and micro operation
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
 
Object-oriented concepts
Object-oriented conceptsObject-oriented concepts
Object-oriented concepts
 
Oops ppt
Oops pptOops ppt
Oops ppt
 

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

Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.
Enam Khan
 
class c++
class c++class c++
class c++
vinay chauhan
 
Lecture 2 (1)
Lecture 2 (1)Lecture 2 (1)
Lecture 2 (1)
zahid khan
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
SURBHI SAROHA
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
Marlom46
 
OOP Week 3 Lecture 2.pptx
OOP Week 3 Lecture 2.pptxOOP Week 3 Lecture 2.pptx
OOP Week 3 Lecture 2.pptx
whoiam36
 
chapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfchapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdf
study material
 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentation
nafisa rahman
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
oop lecture 3
oop lecture 3oop lecture 3
oop lecture 3
Atif Khan
 
Lecture-11 Friend Functions and inline functions.pptx
Lecture-11 Friend Functions and inline functions.pptxLecture-11 Friend Functions and inline functions.pptx
Lecture-11 Friend Functions and inline functions.pptx
rayanbabur
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
rprajat007
 
Class and object in C++ By Pawan Thakur
Class and object in C++ By Pawan ThakurClass and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
Govt. P.G. College Dharamshala
 
Class and object
Class and objectClass and object
Class and object
Prof. Dr. K. Adisesha
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methodsfarhan amjad
 
Unit vi(dsc++)
Unit vi(dsc++)Unit vi(dsc++)
Unit vi(dsc++)
Durga Devi
 
OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++
Dev Chauhan
 
+2 CS class and objects
+2 CS class and objects+2 CS class and objects
+2 CS class and objectskhaliledapal
 

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

Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.
 
class c++
class c++class c++
class c++
 
Lecture 2 (1)
Lecture 2 (1)Lecture 2 (1)
Lecture 2 (1)
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
 
OOP Week 3 Lecture 2.pptx
OOP Week 3 Lecture 2.pptxOOP Week 3 Lecture 2.pptx
OOP Week 3 Lecture 2.pptx
 
chapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfchapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdf
 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentation
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
 
oop lecture 3
oop lecture 3oop lecture 3
oop lecture 3
 
ccc
cccccc
ccc
 
Lecture-11 Friend Functions and inline functions.pptx
Lecture-11 Friend Functions and inline functions.pptxLecture-11 Friend Functions and inline functions.pptx
Lecture-11 Friend Functions and inline functions.pptx
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Class and object in C++ By Pawan Thakur
Class and object in C++ By Pawan ThakurClass and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
 
Class and object
Class and objectClass and object
Class and object
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
 
Unit vi(dsc++)
Unit vi(dsc++)Unit vi(dsc++)
Unit vi(dsc++)
 
OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++
 
cse l 5.pptx
cse l 5.pptxcse l 5.pptx
cse l 5.pptx
 
+2 CS class and objects
+2 CS class and objects+2 CS class and objects
+2 CS class and objects
 

Recently uploaded

MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
JEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questionsJEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questions
ShivajiThube2
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 

Recently uploaded (20)

MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
JEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questionsJEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questions
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 

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: shzadyounas@gmail.com
  • 2.
  • 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(); }