SlideShare a Scribd company logo
Chapter 9
Pointers, Virtual functions &
Polymorphism
Page  2
Contents
•Introduction
•Pointers
•Pointers to objects
•this pointers
•pointers to derived class
•virtual functions
•pure virtual function
Page  3
Early Binding or
Compile Time Polymorphism
 The concept of polymorphism is implemented
using overloaded functions and operators.
 The overloaded memberfunctions are selected
forinvoking by matching arguments, both type
and numbers.
 This information is known to the compilerat the
compile time and, therefore, compileris able to
select the appropriate function fora particular
call at the compile time itself.
 This is called early binding orstatic binding or
static linking.
Page  4
Late Binding or
Run Time Polymorphism
class A
{
int x;
public:
void show( ) {……}
};
class B : public A
{
int y;
public:
void show( ) {……}
};
 Since the prototype of
show( ) is the same in
both the places, the
function is not
overloaded and therefore
static binding does not
apply.
 The class resolution
operatoris used to
specify the class while
invoking the functions
with the derived class.
 Appropriate member
function is selected while
the program is running.
Page  5
Late Binding or
Run Time Polymorphism
 The appropriate version of
function will be invoked at
runtime.
 Since the function is linked
with a particularclass
much laterafterthe
compilation, this process is
termed as late binding.
 This also known as
dynamic binding, since the
selection of appropriate
function is done
Polymorphism
Compile time Run time
Function
Overloading
Operator
Overloading
Virtual
Functions
Achieving Polymorphism
Page  6
Pointer To Objects
 item * it_ptr; whereitemis aclass andit_ptris apointerof
typeitem.
 Object pointers are useful in creats objects at run time.
 An object pointercan be used to access the public
members of an object.
Page  7
Pointer To Objects
class item
{
int code;
float price;
public:
void getdata( int a, float b )
{ code =a; price = b;}
void show( void )
{ cout << “Code :” <<
code<<endl;
<< “Price :” << price <<
endl; }
};
item x;
item *ptr = &x;
 We can referto the
memberfunctions of item
in two ways:
 Using dot operatorand
object.
 x.getdata(100,75.50);
 x.show( );
 Using arrow operatorand
object pointer.
 ptr-> getdata(100,
75.50);
 ptr-> show( );
 Since *ptris an alias of x
 (*ptr).show( );
continue…
Page  8
Pointer To Objects
 We can also create the objects using pointers and new
operator as:
 item * ptr = new item ;
 This statement allocates enough memory for the data members in
the object structure and assigns the address of the memory space
to ptr.
 We can also create an array of objects using pointers
 Item *ptr = new item[10];
 Creates memory space for an array of 10 objects of item.
continue…
9
Thank You !!!
By:-Gourav Kottawar
9
Thank You !!!
By:-Gourav Kottawar

More Related Content

PPTX
Pointers,virtual functions and polymorphism cpp
rajshreemuthiah
 
PPTX
Pointers, virtual function and polymorphism
lalithambiga kamaraj
 
PPTX
07. Virtual Functions
Haresh Jaiswal
 
PPTX
Abstract Base Class and Polymorphism in C++
Liju Thomas
 
PPTX
pointer, virtual function and polymorphism
ramya marichamy
 
PDF
Operator overloading
Pranali Chaudhari
 
PPTX
Virtual function in C++ Pure Virtual Function
Kamlesh Makvana
 
PPTX
constructor & destructor in cpp
gourav kottawar
 
Pointers,virtual functions and polymorphism cpp
rajshreemuthiah
 
Pointers, virtual function and polymorphism
lalithambiga kamaraj
 
07. Virtual Functions
Haresh Jaiswal
 
Abstract Base Class and Polymorphism in C++
Liju Thomas
 
pointer, virtual function and polymorphism
ramya marichamy
 
Operator overloading
Pranali Chaudhari
 
Virtual function in C++ Pure Virtual Function
Kamlesh Makvana
 
constructor & destructor in cpp
gourav kottawar
 

What's hot (20)

DOCX
Virtual function
harman kaur
 
PPT
16 virtual function
Docent Education
 
PPTX
Pointer and polymorphism
SangeethaSasi1
 
PDF
03 function overloading
Jasleen Kaur (Chandigarh University)
 
PDF
Functions in C++
Pranali Chaudhari
 
PDF
Chapter27 polymorphism-virtual-function-abstract-class
Deepak Singh
 
PDF
Virtual Functions
Roman Okolovich
 
PPT
C++: Constructor, Copy Constructor and Assignment operator
Jussi Pohjolainen
 
PDF
Introduction to C++
Pranali Chaudhari
 
PPTX
Polymorphism
Kumar Gaurav
 
PPTX
C++ concept of Polymorphism
kiran Patel
 
PPTX
Compile time polymorphism
ForwardBlog Enewzletter
 
PPT
Lec 42.43 - virtual.functions
Princess Sam
 
PPT
C++: inheritance, composition, polymorphism
Jussi Pohjolainen
 
PPTX
Polymorphism
Amir Ali
 
PPTX
#OOP_D_ITS - 4th - C++ Oop And Class Structure
Hadziq Fabroyir
 
PPTX
expression in cpp
gourav kottawar
 
PDF
Operator overloading in C++
Ilio Catallo
 
PPTX
classes & objects in cpp overview
gourav kottawar
 
PPTX
operator overloading & type conversion in cpp over view || c++
gourav kottawar
 
Virtual function
harman kaur
 
16 virtual function
Docent Education
 
Pointer and polymorphism
SangeethaSasi1
 
03 function overloading
Jasleen Kaur (Chandigarh University)
 
Functions in C++
Pranali Chaudhari
 
Chapter27 polymorphism-virtual-function-abstract-class
Deepak Singh
 
Virtual Functions
Roman Okolovich
 
C++: Constructor, Copy Constructor and Assignment operator
Jussi Pohjolainen
 
Introduction to C++
Pranali Chaudhari
 
Polymorphism
Kumar Gaurav
 
C++ concept of Polymorphism
kiran Patel
 
Compile time polymorphism
ForwardBlog Enewzletter
 
Lec 42.43 - virtual.functions
Princess Sam
 
C++: inheritance, composition, polymorphism
Jussi Pohjolainen
 
Polymorphism
Amir Ali
 
#OOP_D_ITS - 4th - C++ Oop And Class Structure
Hadziq Fabroyir
 
expression in cpp
gourav kottawar
 
Operator overloading in C++
Ilio Catallo
 
classes & objects in cpp overview
gourav kottawar
 
operator overloading & type conversion in cpp over view || c++
gourav kottawar
 
Ad

Viewers also liked (20)

PPTX
pointers,virtual functions and polymorphism
rattaj
 
PPTX
Virtual base class
Tech_MX
 
PPT
C++ polymorphism
Ganesh Hogade
 
PPTX
Uid
Tech_MX
 
PPT
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
cprogrammings
 
PPTX
Seminar on polymorphism
023henil
 
PPTX
Lecture 7, c++(complete reference,herbet sheidt)chapter-17.
Abu Saleh
 
PPT
Static and Dynamic polymorphism in C++
Anil Bapat
 
PPTX
Inheritance in C++
Laxman Puri
 
PPTX
Inheritance
Sapna Sharma
 
PPTX
operator overloading in c++
harman kaur
 
PPTX
Operator overloading
Kumar
 
PPT
Polymorphism
Duane Wesley
 
PPT
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
cprogrammings
 
PPT
C++ Inheritance
Jussi Pohjolainen
 
PPT
Lec 45.46- virtual.functions
Princess Sam
 
PPTX
Inline function in C++
Jenish Patel
 
PDF
OOP in C - Virtual Function (Chinese Version)
Kai-Feng Chou
 
pointers,virtual functions and polymorphism
rattaj
 
Virtual base class
Tech_MX
 
C++ polymorphism
Ganesh Hogade
 
Uid
Tech_MX
 
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
cprogrammings
 
Seminar on polymorphism
023henil
 
Lecture 7, c++(complete reference,herbet sheidt)chapter-17.
Abu Saleh
 
Static and Dynamic polymorphism in C++
Anil Bapat
 
Inheritance in C++
Laxman Puri
 
Inheritance
Sapna Sharma
 
operator overloading in c++
harman kaur
 
Operator overloading
Kumar
 
Polymorphism
Duane Wesley
 
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
cprogrammings
 
C++ Inheritance
Jussi Pohjolainen
 
Lec 45.46- virtual.functions
Princess Sam
 
Inline function in C++
Jenish Patel
 
OOP in C - Virtual Function (Chinese Version)
Kai-Feng Chou
 
Ad

Similar to pointers, virtual functions and polymorphisms in c++ || in cpp (20)

PPTX
C++ Class & object pointer in c++ programming language
HariTharshiniBscIT1
 
DOCX
C questions
parm112
 
PPT
Virtual Function and Polymorphism.ppt
ishan743441
 
PPTX
6be10b153306cc41e65403247a14a4dba5f9186aCHAPTER 2_POINTERS, VIRTUAL FUNCTIONS...
Mysteriousexpert
 
PPSX
Object oriented concepts & programming (2620003)
nirajmandaliya
 
DOCX
New microsoft office word document (2)
rashmita_mishra
 
PDF
Polymorphism
SherabGyatso
 
PDF
C++ Object oriented concepts & programming
nirajmandaliya
 
PPTX
Polymorphismupload
Mukhtar_Hunzai
 
PDF
22 scheme OOPs with C++ BCS306B_module2.pdfmodule2.pdf
sindhus795217
 
PPTX
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Abu Saleh
 
PDF
polymorphism in c++ with Full Explanation.
UdayGumre
 
PPTX
2.dynamic
bashcode
 
PPTX
OOC MODULE1.pptx
1HK19CS090MOHAMMEDSA
 
PDF
polymorphism for b.tech iii year students
Somesh Kumar
 
PPTX
Virtual function
zindadili
 
PPT
Presentation
manogallery
 
PPTX
Object oriented programming slides for presentation
abdullahkhann3534
 
PDF
Unit3_OOP-converted.pdf
PowerfullBoy1
 
PDF
chapter-8-function-overloading.pdf
study material
 
C++ Class & object pointer in c++ programming language
HariTharshiniBscIT1
 
C questions
parm112
 
Virtual Function and Polymorphism.ppt
ishan743441
 
6be10b153306cc41e65403247a14a4dba5f9186aCHAPTER 2_POINTERS, VIRTUAL FUNCTIONS...
Mysteriousexpert
 
Object oriented concepts & programming (2620003)
nirajmandaliya
 
New microsoft office word document (2)
rashmita_mishra
 
Polymorphism
SherabGyatso
 
C++ Object oriented concepts & programming
nirajmandaliya
 
Polymorphismupload
Mukhtar_Hunzai
 
22 scheme OOPs with C++ BCS306B_module2.pdfmodule2.pdf
sindhus795217
 
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Abu Saleh
 
polymorphism in c++ with Full Explanation.
UdayGumre
 
2.dynamic
bashcode
 
OOC MODULE1.pptx
1HK19CS090MOHAMMEDSA
 
polymorphism for b.tech iii year students
Somesh Kumar
 
Virtual function
zindadili
 
Presentation
manogallery
 
Object oriented programming slides for presentation
abdullahkhann3534
 
Unit3_OOP-converted.pdf
PowerfullBoy1
 
chapter-8-function-overloading.pdf
study material
 

More from gourav kottawar (20)

PPTX
operator overloading & type conversion in cpp
gourav kottawar
 
PPTX
constructor & destructor in cpp
gourav kottawar
 
PPTX
classes & objects in cpp
gourav kottawar
 
PPTX
expression in cpp
gourav kottawar
 
PPTX
basics of c++
gourav kottawar
 
PPT
working file handling in cpp overview
gourav kottawar
 
PPTX
exception handling in cpp
gourav kottawar
 
PPT
cpp input & output system basics
gourav kottawar
 
PPTX
basics of c++
gourav kottawar
 
PPT
SQL || overview and detailed information about Sql
gourav kottawar
 
PPT
SQL querys in detail || Sql query slides
gourav kottawar
 
PPT
Rrelational algebra in dbms overview
gourav kottawar
 
PPT
overview of database concept
gourav kottawar
 
PPT
Relational Model in dbms & sql database
gourav kottawar
 
PPTX
DBMS information in detail || Dbms (lab) ppt
gourav kottawar
 
PPTX
security and privacy in dbms and in sql database
gourav kottawar
 
PPT
The system development life cycle (SDLC)
gourav kottawar
 
PPT
Software documentation
gourav kottawar
 
PPT
Software reengineering
gourav kottawar
 
PPTX
Organizational behaviour
gourav kottawar
 
operator overloading & type conversion in cpp
gourav kottawar
 
constructor & destructor in cpp
gourav kottawar
 
classes & objects in cpp
gourav kottawar
 
expression in cpp
gourav kottawar
 
basics of c++
gourav kottawar
 
working file handling in cpp overview
gourav kottawar
 
exception handling in cpp
gourav kottawar
 
cpp input & output system basics
gourav kottawar
 
basics of c++
gourav kottawar
 
SQL || overview and detailed information about Sql
gourav kottawar
 
SQL querys in detail || Sql query slides
gourav kottawar
 
Rrelational algebra in dbms overview
gourav kottawar
 
overview of database concept
gourav kottawar
 
Relational Model in dbms & sql database
gourav kottawar
 
DBMS information in detail || Dbms (lab) ppt
gourav kottawar
 
security and privacy in dbms and in sql database
gourav kottawar
 
The system development life cycle (SDLC)
gourav kottawar
 
Software documentation
gourav kottawar
 
Software reengineering
gourav kottawar
 
Organizational behaviour
gourav kottawar
 

Recently uploaded (20)

PPTX
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Autodock-for-Beginners by Rahul D Jawarkar.pptx
Rahul Jawarkar
 
PDF
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
PPTX
CDH. pptx
AneetaSharma15
 
PPTX
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
PDF
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Autodock-for-Beginners by Rahul D Jawarkar.pptx
Rahul Jawarkar
 
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
CDH. pptx
AneetaSharma15
 
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 

pointers, virtual functions and polymorphisms in c++ || in cpp

  • 1. Chapter 9 Pointers, Virtual functions & Polymorphism
  • 2. Page  2 Contents •Introduction •Pointers •Pointers to objects •this pointers •pointers to derived class •virtual functions •pure virtual function
  • 3. Page  3 Early Binding or Compile Time Polymorphism  The concept of polymorphism is implemented using overloaded functions and operators.  The overloaded memberfunctions are selected forinvoking by matching arguments, both type and numbers.  This information is known to the compilerat the compile time and, therefore, compileris able to select the appropriate function fora particular call at the compile time itself.  This is called early binding orstatic binding or static linking.
  • 4. Page  4 Late Binding or Run Time Polymorphism class A { int x; public: void show( ) {……} }; class B : public A { int y; public: void show( ) {……} };  Since the prototype of show( ) is the same in both the places, the function is not overloaded and therefore static binding does not apply.  The class resolution operatoris used to specify the class while invoking the functions with the derived class.  Appropriate member function is selected while the program is running.
  • 5. Page  5 Late Binding or Run Time Polymorphism  The appropriate version of function will be invoked at runtime.  Since the function is linked with a particularclass much laterafterthe compilation, this process is termed as late binding.  This also known as dynamic binding, since the selection of appropriate function is done Polymorphism Compile time Run time Function Overloading Operator Overloading Virtual Functions Achieving Polymorphism
  • 6. Page  6 Pointer To Objects  item * it_ptr; whereitemis aclass andit_ptris apointerof typeitem.  Object pointers are useful in creats objects at run time.  An object pointercan be used to access the public members of an object.
  • 7. Page  7 Pointer To Objects class item { int code; float price; public: void getdata( int a, float b ) { code =a; price = b;} void show( void ) { cout << “Code :” << code<<endl; << “Price :” << price << endl; } }; item x; item *ptr = &x;  We can referto the memberfunctions of item in two ways:  Using dot operatorand object.  x.getdata(100,75.50);  x.show( );  Using arrow operatorand object pointer.  ptr-> getdata(100, 75.50);  ptr-> show( );  Since *ptris an alias of x  (*ptr).show( ); continue…
  • 8. Page  8 Pointer To Objects  We can also create the objects using pointers and new operator as:  item * ptr = new item ;  This statement allocates enough memory for the data members in the object structure and assigns the address of the memory space to ptr.  We can also create an array of objects using pointers  Item *ptr = new item[10];  Creates memory space for an array of 10 objects of item. continue…