SlideShare a Scribd company logo
1 of 20
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

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 objectsAnil Kumar
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in JavaKurapati Vishwak
 
Inheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphismInheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphismJawad Khan
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member FunctionsMuhammad 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 implementationHoneyChintal
 
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 KuteTushar 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 AccessingMuhammad Hammad Waseem
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentationtigerwarn
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in javaElizabeth alexander
 
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
البرمجة الهدفية بلغة جافا - مفاهيم أساسية البرمجة الهدفية بلغة جافا - مفاهيم أساسية
البرمجة الهدفية بلغة جافا - مفاهيم أساسية Mahmoud Alfarra
 

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

Object Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesObject Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesFellowBuddy.com
 
Safety rules and earthing
Safety rules and earthingSafety rules and earthing
Safety rules and earthingNikhil 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 ComputationNikhil Pandit
 
Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default argumentsNikhil Pandit
 
Software Coding- Software Coding
Software Coding- Software CodingSoftware Coding- Software Coding
Software Coding- Software CodingNikhil Pandit
 
CHAIN RULE AND IMPLICIT FUNCTION
CHAIN RULE AND IMPLICIT FUNCTIONCHAIN RULE AND IMPLICIT FUNCTION
CHAIN RULE AND IMPLICIT FUNCTIONNikhil Pandit
 
The scope of contribution
The scope of contributionThe scope of contribution
The scope of contributionNikhil Pandit
 
4 stroke diesel engine
4 stroke diesel engine4 stroke diesel engine
4 stroke diesel engineNikhil Pandit
 
Use case Diagram and Sequence Diagram
Use case Diagram and Sequence DiagramUse case Diagram and Sequence Diagram
Use case Diagram and Sequence DiagramNikhil Pandit
 
Counterfort Retaining Wall
Counterfort Retaining WallCounterfort Retaining Wall
Counterfort Retaining WallKaizer Dave
 
Register transfer and micro-operation
Register transfer and micro-operationRegister transfer and micro-operation
Register transfer and micro-operationNikhil Pandit
 
Register transfer and micro operation
Register transfer and micro operationRegister transfer and micro operation
Register transfer and micro operationKamal Acharya
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).pptAlok Kumar
 

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
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functionsMarlom46
 
OOP Week 3 Lecture 2.pptx
OOP Week 3 Lecture 2.pptxOOP Week 3 Lecture 2.pptx
OOP Week 3 Lecture 2.pptxwhoiam36
 
chapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfchapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfstudy material
 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentationnafisa 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 SCIENCEVenugopalavarma Raja
 
oop lecture 3
oop lecture 3oop lecture 3
oop lecture 3Atif 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.pptxrayanbabur
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 
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

SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxdhanalakshmis0310
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 

Recently uploaded (20)

SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 

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(); }