SlideShare uma empresa Scribd logo
1 de 38
Dr. BABASAHEB AMBEDKAR TECHNOLOGICAL UNIVERSITY
                Presentation on


Pointers , Virtual Functions and Polymorphism.
                       By ,
                                Ruturaj Nalawade
                            Sanjay Bidkar
                            Swapnil Sarwade
                      Under the Guidance of ,
                            Mrs . Ladda
POINTERS
INTRODUCTION
Pointers are the variables which
 holds the addresses of other
 variables.

Pointer variables are denoted by
  „ * ptr ‟

Pointers are the derived data types.
INTRODUCTION – CONT.
E.g. :=
{
          int i , *j;
          i= 3;
          j = &i;
          cout<<“The value of i is t”<<i<<endl;
          cout<<“The value of *j is t”<<*j;
}

Output : :

The value of i is      3
The value of *j is     3
INTRODUCTION – CONT.
E.g. :=
{
          int i , *j;
          i= 3;
          j = &i;
          cout<<“The value of i is t”<<i<<endl;
          cout<<“The value of *j is t”<<*j; * j
}

Output : :

The value of i is      3
The value of *j is     3
Introduction - Cont.
 How the *j gets the value of i ?

int i , *j ;




Variable                      i        j
Names
Value

Memory                      65524    65522
Address
Introduction - Cont.
 How the *j gets the value of i ?

int i , *j ;
i=3;




Variable                      i        j
Names
Value                         3

Memory                      65524    65522
Address
Introduction - Cont.
 How the *j gets the value of i ?

int i , *j ;
i=3;
j=&i;


Variable                      i            j
Names
Value                         3          65524

Memory                      65524        65522
Address




  *j refers to the value at address j.
INTRODUCTION – CONT.

Pointers are used for memory management and
  achieving polymorphism.

C++  adds the concept of
CONSTANT POINTER
 & POINTER TO A CONSTANT . :=
INTRODUCTION - CONT.



1. Constant Pointer      ::

Declaration   =

              data type * const pointer
INTRODUCTION - CONT.
2.   Pointer to a Constant ::

              data type const * pointer



3.   const data type * const pointer
POINTERS       TO   OBJECTS -

Pointers can point to an object created by
 class .

   Declaration : classname object;
                  classname * pointer;

  Definition    : pointer = & object;
POINTERS TO OBJECTS - CONT.

Object pointers are useful in creating
 objects at run time.



We can also use an object pointer to access
 the public members & member function of
 an object , by using „->‟ operator and the
 object pointer .
POINTERS       TO   OBJECTS –CONT.

E.g.
       pointer -> getdata( );

We can also use

       ( * pointer ) . function( );
THIS POINTER

C++ uses keyword „ this ‟ to represent an
 object that invokes a member function.

E.g. The function call A. max( ) will set the
 pointer this to the address of the object A.

E.g. To access private variables inside a
 member function
           a=123;                       or
           this -> a = 123;
THIS POINTER - APPLICATIONS
In operator overloading using member
 function we use implicitly 'this‟ pointer.



The another important application of the
 pointer 'this' is to return the object it points
 to .
POINTERS TO DERIVED CLASS
Pointers to objects of a base class are type
 compatible with pointers to objects of a
 derived class.

A single pointer variable can be made to
 point to objects belonging to different
 classes.
POINTERS TO DERIVED CLASS – CONT.

e.g.
        B *cptr;
        B b;
        D d;
        cptr = & b;
we can also make cptr to point to the object d
 as follows:
    cptr = & d
POINTERS TO DERIVED CLASS – CONT.

  Base Class
                          Derived Class
Public:
a,b
                        Public / Private /
Private /               Protected :
Protected:
c,d                     e,f,g,h

 If cptr = & d;

        cptr      a,b
POINTERS TO DERIVED CLASS – CONT.


This shows that , although a base pointer
  can be made to point to any number of
  derived objects, it can not directly access
  the members defined by a derived class.


To access the members defined by a
  derived class , cast base pointer to the
  derived class type.
POINTERS TO DERIVED CLASS – CONT.


 E.g   . Casting

        dptr -> show ( ) ;

        ( ( DC * ) bptr ) -> show ( ) ;
VIRTUAL FUNCTIONS
VIRTUAL FUNCTION

The application of polymorphism is the
 ability to refer the objects without any regard
 to their classes.



This necessitates the use of a single
 pointer variable to refer to the objects of
 different classes.
VIRTUAL FUNCTION – CONT.
By making the function 'virtual' in base
 class C++ determines which function to use
 at run time based on the type of object
 pointed to by the base pointer , rather than
 the type of the pointer.

Runtime polymorphism is achieved only
 when a virtual function is accessed through
 a pointer to the base class.
VIRTUAL FUNCTIONS - RULES

1. The virtual functions must be members of
     some class.
2.   They cannot be static members.
3.   They are accessed by using object
     pointers.
4.   A virtual function can be friend of other
     function.
5.   A virtual function in a base class must be
     defined , even though it may not be used.
RULES –CONT.
6. We cannot have a virtual constructors, but
  we can have virtual destructors.



7. While a base pointer can point to any type
  of derived object, the reverse is not true.
RULES –CONT.
8. The prototypes of the base class version
   of a virtual function and all the derived
   class versions must be identical.



9. When a base pointer points to a derived
   class , incrementing or decrementing it will
   not make it to point to the next object of
   the derived class.
RULES –CONT.



10.If a virtual function is define in the base
   class ,it need not be necessarily redefined
   in the derived class.
POLYMORPHISM
POLYMORPHISM

 Polymorphism is crucial feature of Object
   Oriented Programming.



 Polymorphism simply means one name
   having multiple forms.
POLYMORPHISM - CONT.

 “Polymorphism   is the genie in OOP who
 takes instruction from clients and properly
 interprets their wishes.”

–   Ira Pohl, “Object Oriented Programming
 using C++”.
POLYMORPHISM – CONT.

Definition:

     Polymorphism is the ability to create a
 variable, a function or an object that has
 more than one form.
EXAMPLE:

For example:

 The + (plus) operator in C++:
    4+5         <-- Integer addition
    3.14 + 2.0 <-- Floating point addition
    s1 + "bar" <-- String concatenation!
TYPES OF POLYMORPHISM



     Compile-time     Run-time
     Polymorphism   Polymorphism
TYPES OF POLYMORPHISM
 In
   compile time polymorphism, compiler is
 able to select the appropriate function a
 particular call at the compile time.

 In
   run time polymorphism, an appropriate
 member function is selected while the
 program is running.
BENEFITS OF POLYMORPHISM

 Simplicity:
This makes your code easier for you to write
 and easier for others to understand.

 Extensibility:

Polymorphism design and implements system
 that are more extensible.
REFERENCES :

Let us C++
             – by Yeshwant Kanetkar.

Object Oriented Programming with C++
             –by E . BALAGURUSAMY.

Internet.
THANK YOU !!

Mais conteúdo relacionado

Mais procurados

Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member FunctionsMOHIT AGARWAL
 
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...Edureka!
 
Polymorphism in C++
Polymorphism in C++Polymorphism in C++
Polymorphism in C++Rabin BK
 
Type casting in java
Type casting in javaType casting in java
Type casting in javaFarooq Baloch
 
Classes and objects
Classes and objectsClasses and objects
Classes and objectsNilesh Dalvi
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statementsSaad Sheikh
 
virtual function
virtual functionvirtual function
virtual functionVENNILAV6
 
Operator overloading
Operator overloadingOperator overloading
Operator overloadingArunaDevi63
 
Data Type Conversion in C++
Data Type Conversion in C++Data Type Conversion in C++
Data Type Conversion in C++Danial Mirza
 
Visibility control in java
Visibility control in javaVisibility control in java
Visibility control in javaTech_MX
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in pythonRaginiJain21
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT03062679929
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructorsNilesh Dalvi
 

Mais procurados (20)

Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
Polymorphism in C++
Polymorphism in C++Polymorphism in C++
Polymorphism in C++
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
virtual function
virtual functionvirtual function
virtual function
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Data Type Conversion in C++
Data Type Conversion in C++Data Type Conversion in C++
Data Type Conversion in C++
 
Visibility control in java
Visibility control in javaVisibility control in java
Visibility control in java
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Methods in java
Methods in javaMethods in java
Methods in java
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
 
Strings in python
Strings in pythonStrings in python
Strings in python
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
 

Destaque

Object Oriented Programming - Abstraction & Encapsulation
Object Oriented Programming - Abstraction & EncapsulationObject Oriented Programming - Abstraction & Encapsulation
Object Oriented Programming - Abstraction & EncapsulationDudy Ali
 
Java multi threading
Java multi threadingJava multi threading
Java multi threadingRaja Sekhar
 
Presentation on generation of languages
Presentation on generation of languagesPresentation on generation of languages
Presentation on generation of languagesRicha Pant
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming languageVasavi College of Engg
 
Pointers, virtual function and polymorphism
Pointers, virtual function and polymorphismPointers, virtual function and polymorphism
Pointers, virtual function and polymorphismlalithambiga kamaraj
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming languageVasavi College of Engg
 

Destaque (9)

08 subprograms
08 subprograms08 subprograms
08 subprograms
 
9 subprograms
9 subprograms9 subprograms
9 subprograms
 
Object Oriented Programming - Abstraction & Encapsulation
Object Oriented Programming - Abstraction & EncapsulationObject Oriented Programming - Abstraction & Encapsulation
Object Oriented Programming - Abstraction & Encapsulation
 
Java multi threading
Java multi threadingJava multi threading
Java multi threading
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Presentation on generation of languages
Presentation on generation of languagesPresentation on generation of languages
Presentation on generation of languages
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming language
 
Pointers, virtual function and polymorphism
Pointers, virtual function and polymorphismPointers, virtual function and polymorphism
Pointers, virtual function and polymorphism
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
 

Semelhante a pointers,virtual functions and polymorphism

pointer, virtual function and polymorphism
pointer, virtual function and polymorphismpointer, virtual function and polymorphism
pointer, virtual function and polymorphismramya marichamy
 
Virtual Function and Polymorphism.ppt
Virtual Function and Polymorphism.pptVirtual Function and Polymorphism.ppt
Virtual Function and Polymorphism.pptishan743441
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpprajshreemuthiah
 
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13Abu Saleh
 
C++ Class & object pointer in c++ programming language
C++ Class & object pointer in c++ programming languageC++ Class & object pointer in c++ programming language
C++ Class & object pointer in c++ programming languageHariTharshiniBscIT1
 
pointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpppointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cppgourav kottawar
 
C questions
C questionsC questions
C questionsparm112
 
2.Types_Variables_Functions.pdf
2.Types_Variables_Functions.pdf2.Types_Variables_Functions.pdf
2.Types_Variables_Functions.pdfTrnThBnhDng
 
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptbtech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptchintuyadav19
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)rashmita_mishra
 
Unit3_OOP-converted.pdf
Unit3_OOP-converted.pdfUnit3_OOP-converted.pdf
Unit3_OOP-converted.pdfPowerfullBoy1
 
Ch.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objectsCh.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objectsITNet
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented TechnologiesUmesh Nikam
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingRai University
 

Semelhante a pointers,virtual functions and polymorphism (20)

Polymorphism
PolymorphismPolymorphism
Polymorphism
 
pointer, virtual function and polymorphism
pointer, virtual function and polymorphismpointer, virtual function and polymorphism
pointer, virtual function and polymorphism
 
Virtual Function and Polymorphism.ppt
Virtual Function and Polymorphism.pptVirtual Function and Polymorphism.ppt
Virtual Function and Polymorphism.ppt
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpp
 
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
 
C++ Class & object pointer in c++ programming language
C++ Class & object pointer in c++ programming languageC++ Class & object pointer in c++ programming language
C++ Class & object pointer in c++ programming language
 
Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4
 
pointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpppointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpp
 
C questions
C questionsC questions
C questions
 
2.Types_Variables_Functions.pdf
2.Types_Variables_Functions.pdf2.Types_Variables_Functions.pdf
2.Types_Variables_Functions.pdf
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
 
Pointers
PointersPointers
Pointers
 
C++ Interview Questions
C++ Interview QuestionsC++ Interview Questions
C++ Interview Questions
 
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptbtech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
 
Unit3_OOP-converted.pdf
Unit3_OOP-converted.pdfUnit3_OOP-converted.pdf
Unit3_OOP-converted.pdf
 
Ch.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objectsCh.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objects
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented Technologies
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
 

Último

Nika Muhl Visa Approval Shirt, Nika Muhl Visa Approval T-Shirt
Nika Muhl Visa Approval Shirt, Nika Muhl Visa Approval T-ShirtNika Muhl Visa Approval Shirt, Nika Muhl Visa Approval T-Shirt
Nika Muhl Visa Approval Shirt, Nika Muhl Visa Approval T-Shirtniherranjansingha
 
Dominican American Coalition PAC Executive Summary
Dominican American Coalition PAC Executive SummaryDominican American Coalition PAC Executive Summary
Dominican American Coalition PAC Executive SummaryRDE GROUP CORP
 
2024 - Love and Madness - a book about love, madness, heartbreak and politics
2024 - Love and Madness - a book about love, madness, heartbreak and politics2024 - Love and Madness - a book about love, madness, heartbreak and politics
2024 - Love and Madness - a book about love, madness, heartbreak and politicsConradSmit5
 
PEACE BETWEEN ISRAEL AND PALESTINE REQUIRES EXTREMISTS OUT OF POWER AND RESTR...
PEACE BETWEEN ISRAEL AND PALESTINE REQUIRES EXTREMISTS OUT OF POWER AND RESTR...PEACE BETWEEN ISRAEL AND PALESTINE REQUIRES EXTREMISTS OUT OF POWER AND RESTR...
PEACE BETWEEN ISRAEL AND PALESTINE REQUIRES EXTREMISTS OUT OF POWER AND RESTR...Faga1939
 
21052024_First India Newspaper Jaipur.pdf
21052024_First India Newspaper Jaipur.pdf21052024_First India Newspaper Jaipur.pdf
21052024_First India Newspaper Jaipur.pdfFIRST INDIA
 
Have A Complimentary Cheat Sheet, On Us!!!
Have A Complimentary Cheat Sheet, On Us!!!Have A Complimentary Cheat Sheet, On Us!!!
Have A Complimentary Cheat Sheet, On Us!!!Abdul-Hakim Shabazz
 
25052024_First India Newspaper Jaipur.pdf
25052024_First India Newspaper Jaipur.pdf25052024_First India Newspaper Jaipur.pdf
25052024_First India Newspaper Jaipur.pdfFIRST INDIA
 
24052024_First India Newspaper Jaipur.pdf
24052024_First India Newspaper Jaipur.pdf24052024_First India Newspaper Jaipur.pdf
24052024_First India Newspaper Jaipur.pdfFIRST INDIA
 
Encore portal Project PPt on live portal
Encore portal Project PPt on live portalEncore portal Project PPt on live portal
Encore portal Project PPt on live portalEshantRawat2
 
israeil_bnetaniahou_panel_report_eng.pdf
israeil_bnetaniahou_panel_report_eng.pdfisraeil_bnetaniahou_panel_report_eng.pdf
israeil_bnetaniahou_panel_report_eng.pdfssuser5750e1
 
R$ 78 milhões: Estado aprova 593 propostas para acordos diretos de precatórios
R$ 78 milhões: Estado aprova 593 propostas para acordos diretos de precatóriosR$ 78 milhões: Estado aprova 593 propostas para acordos diretos de precatórios
R$ 78 milhões: Estado aprova 593 propostas para acordos diretos de precatóriosMaurílio Júnior
 
19052024_First India Newspaper Jaipur.pdf
19052024_First India Newspaper Jaipur.pdf19052024_First India Newspaper Jaipur.pdf
19052024_First India Newspaper Jaipur.pdfFIRST INDIA
 
23052024_First India Newspaper Jaipur.pdf
23052024_First India Newspaper Jaipur.pdf23052024_First India Newspaper Jaipur.pdf
23052024_First India Newspaper Jaipur.pdfFIRST INDIA
 
20052024_First India Newspaper Jaipur.pdf
20052024_First India Newspaper Jaipur.pdf20052024_First India Newspaper Jaipur.pdf
20052024_First India Newspaper Jaipur.pdfFIRST INDIA
 
May 2024 - Crypto Market Report_FINAL.pdf
May 2024 - Crypto Market Report_FINAL.pdfMay 2024 - Crypto Market Report_FINAL.pdf
May 2024 - Crypto Market Report_FINAL.pdfmanisha194592
 
Embed-4-1-1.pdf vm ;sdkp[kdp[kpdkpodp;p;j
Embed-4-1-1.pdf vm ;sdkp[kdp[kpdkpodp;p;jEmbed-4-1-1.pdf vm ;sdkp[kdp[kpdkpodp;p;j
Embed-4-1-1.pdf vm ;sdkp[kdp[kpdkpodp;p;jbhavenpr
 
Embed-4-3 (1).pdf cvxx'f['df[p'lf][l][fl][fl][][l[
Embed-4-3 (1).pdf cvxx'f['df[p'lf][l][fl][fl][][l[Embed-4-3 (1).pdf cvxx'f['df[p'lf][l][fl][fl][][l[
Embed-4-3 (1).pdf cvxx'f['df[p'lf][l][fl][fl][][l[bhavenpr
 
Minnesota Timberwolves Bring Ya Ass T Shirt
Minnesota Timberwolves Bring Ya Ass T ShirtMinnesota Timberwolves Bring Ya Ass T Shirt
Minnesota Timberwolves Bring Ya Ass T Shirtniherranjansingha
 
Meta_AI_ads_investigation.pdfldoljjwejolejolol
Meta_AI_ads_investigation.pdfldoljjwejolejololMeta_AI_ads_investigation.pdfldoljjwejolejolol
Meta_AI_ads_investigation.pdfldoljjwejolejololbhavenpr
 
Embed-3-1-1.pdf The ECI direction on April 2, 2024 can be read here:
Embed-3-1-1.pdf  The ECI direction on April 2, 2024 can be read here:Embed-3-1-1.pdf  The ECI direction on April 2, 2024 can be read here:
Embed-3-1-1.pdf The ECI direction on April 2, 2024 can be read here:bhavenpr
 

Último (20)

Nika Muhl Visa Approval Shirt, Nika Muhl Visa Approval T-Shirt
Nika Muhl Visa Approval Shirt, Nika Muhl Visa Approval T-ShirtNika Muhl Visa Approval Shirt, Nika Muhl Visa Approval T-Shirt
Nika Muhl Visa Approval Shirt, Nika Muhl Visa Approval T-Shirt
 
Dominican American Coalition PAC Executive Summary
Dominican American Coalition PAC Executive SummaryDominican American Coalition PAC Executive Summary
Dominican American Coalition PAC Executive Summary
 
2024 - Love and Madness - a book about love, madness, heartbreak and politics
2024 - Love and Madness - a book about love, madness, heartbreak and politics2024 - Love and Madness - a book about love, madness, heartbreak and politics
2024 - Love and Madness - a book about love, madness, heartbreak and politics
 
PEACE BETWEEN ISRAEL AND PALESTINE REQUIRES EXTREMISTS OUT OF POWER AND RESTR...
PEACE BETWEEN ISRAEL AND PALESTINE REQUIRES EXTREMISTS OUT OF POWER AND RESTR...PEACE BETWEEN ISRAEL AND PALESTINE REQUIRES EXTREMISTS OUT OF POWER AND RESTR...
PEACE BETWEEN ISRAEL AND PALESTINE REQUIRES EXTREMISTS OUT OF POWER AND RESTR...
 
21052024_First India Newspaper Jaipur.pdf
21052024_First India Newspaper Jaipur.pdf21052024_First India Newspaper Jaipur.pdf
21052024_First India Newspaper Jaipur.pdf
 
Have A Complimentary Cheat Sheet, On Us!!!
Have A Complimentary Cheat Sheet, On Us!!!Have A Complimentary Cheat Sheet, On Us!!!
Have A Complimentary Cheat Sheet, On Us!!!
 
25052024_First India Newspaper Jaipur.pdf
25052024_First India Newspaper Jaipur.pdf25052024_First India Newspaper Jaipur.pdf
25052024_First India Newspaper Jaipur.pdf
 
24052024_First India Newspaper Jaipur.pdf
24052024_First India Newspaper Jaipur.pdf24052024_First India Newspaper Jaipur.pdf
24052024_First India Newspaper Jaipur.pdf
 
Encore portal Project PPt on live portal
Encore portal Project PPt on live portalEncore portal Project PPt on live portal
Encore portal Project PPt on live portal
 
israeil_bnetaniahou_panel_report_eng.pdf
israeil_bnetaniahou_panel_report_eng.pdfisraeil_bnetaniahou_panel_report_eng.pdf
israeil_bnetaniahou_panel_report_eng.pdf
 
R$ 78 milhões: Estado aprova 593 propostas para acordos diretos de precatórios
R$ 78 milhões: Estado aprova 593 propostas para acordos diretos de precatóriosR$ 78 milhões: Estado aprova 593 propostas para acordos diretos de precatórios
R$ 78 milhões: Estado aprova 593 propostas para acordos diretos de precatórios
 
19052024_First India Newspaper Jaipur.pdf
19052024_First India Newspaper Jaipur.pdf19052024_First India Newspaper Jaipur.pdf
19052024_First India Newspaper Jaipur.pdf
 
23052024_First India Newspaper Jaipur.pdf
23052024_First India Newspaper Jaipur.pdf23052024_First India Newspaper Jaipur.pdf
23052024_First India Newspaper Jaipur.pdf
 
20052024_First India Newspaper Jaipur.pdf
20052024_First India Newspaper Jaipur.pdf20052024_First India Newspaper Jaipur.pdf
20052024_First India Newspaper Jaipur.pdf
 
May 2024 - Crypto Market Report_FINAL.pdf
May 2024 - Crypto Market Report_FINAL.pdfMay 2024 - Crypto Market Report_FINAL.pdf
May 2024 - Crypto Market Report_FINAL.pdf
 
Embed-4-1-1.pdf vm ;sdkp[kdp[kpdkpodp;p;j
Embed-4-1-1.pdf vm ;sdkp[kdp[kpdkpodp;p;jEmbed-4-1-1.pdf vm ;sdkp[kdp[kpdkpodp;p;j
Embed-4-1-1.pdf vm ;sdkp[kdp[kpdkpodp;p;j
 
Embed-4-3 (1).pdf cvxx'f['df[p'lf][l][fl][fl][][l[
Embed-4-3 (1).pdf cvxx'f['df[p'lf][l][fl][fl][][l[Embed-4-3 (1).pdf cvxx'f['df[p'lf][l][fl][fl][][l[
Embed-4-3 (1).pdf cvxx'f['df[p'lf][l][fl][fl][][l[
 
Minnesota Timberwolves Bring Ya Ass T Shirt
Minnesota Timberwolves Bring Ya Ass T ShirtMinnesota Timberwolves Bring Ya Ass T Shirt
Minnesota Timberwolves Bring Ya Ass T Shirt
 
Meta_AI_ads_investigation.pdfldoljjwejolejolol
Meta_AI_ads_investigation.pdfldoljjwejolejololMeta_AI_ads_investigation.pdfldoljjwejolejolol
Meta_AI_ads_investigation.pdfldoljjwejolejolol
 
Embed-3-1-1.pdf The ECI direction on April 2, 2024 can be read here:
Embed-3-1-1.pdf  The ECI direction on April 2, 2024 can be read here:Embed-3-1-1.pdf  The ECI direction on April 2, 2024 can be read here:
Embed-3-1-1.pdf The ECI direction on April 2, 2024 can be read here:
 

pointers,virtual functions and polymorphism

  • 1. Dr. BABASAHEB AMBEDKAR TECHNOLOGICAL UNIVERSITY Presentation on Pointers , Virtual Functions and Polymorphism. By , Ruturaj Nalawade Sanjay Bidkar Swapnil Sarwade Under the Guidance of , Mrs . Ladda
  • 3. INTRODUCTION Pointers are the variables which holds the addresses of other variables. Pointer variables are denoted by „ * ptr ‟ Pointers are the derived data types.
  • 4. INTRODUCTION – CONT. E.g. := { int i , *j; i= 3; j = &i; cout<<“The value of i is t”<<i<<endl; cout<<“The value of *j is t”<<*j; } Output : : The value of i is 3 The value of *j is 3
  • 5. INTRODUCTION – CONT. E.g. := { int i , *j; i= 3; j = &i; cout<<“The value of i is t”<<i<<endl; cout<<“The value of *j is t”<<*j; * j } Output : : The value of i is 3 The value of *j is 3
  • 6. Introduction - Cont.  How the *j gets the value of i ? int i , *j ; Variable i j Names Value Memory 65524 65522 Address
  • 7. Introduction - Cont.  How the *j gets the value of i ? int i , *j ; i=3; Variable i j Names Value 3 Memory 65524 65522 Address
  • 8. Introduction - Cont.  How the *j gets the value of i ? int i , *j ; i=3; j=&i; Variable i j Names Value 3 65524 Memory 65524 65522 Address *j refers to the value at address j.
  • 9. INTRODUCTION – CONT. Pointers are used for memory management and achieving polymorphism. C++ adds the concept of CONSTANT POINTER & POINTER TO A CONSTANT . :=
  • 10. INTRODUCTION - CONT. 1. Constant Pointer :: Declaration = data type * const pointer
  • 11. INTRODUCTION - CONT. 2. Pointer to a Constant :: data type const * pointer 3. const data type * const pointer
  • 12. POINTERS TO OBJECTS - Pointers can point to an object created by class . Declaration : classname object; classname * pointer; Definition : pointer = & object;
  • 13. POINTERS TO OBJECTS - CONT. Object pointers are useful in creating objects at run time. We can also use an object pointer to access the public members & member function of an object , by using „->‟ operator and the object pointer .
  • 14. POINTERS TO OBJECTS –CONT. E.g. pointer -> getdata( ); We can also use ( * pointer ) . function( );
  • 15. THIS POINTER C++ uses keyword „ this ‟ to represent an object that invokes a member function. E.g. The function call A. max( ) will set the pointer this to the address of the object A. E.g. To access private variables inside a member function a=123; or this -> a = 123;
  • 16. THIS POINTER - APPLICATIONS In operator overloading using member function we use implicitly 'this‟ pointer. The another important application of the pointer 'this' is to return the object it points to .
  • 17. POINTERS TO DERIVED CLASS Pointers to objects of a base class are type compatible with pointers to objects of a derived class. A single pointer variable can be made to point to objects belonging to different classes.
  • 18. POINTERS TO DERIVED CLASS – CONT. e.g. B *cptr; B b; D d; cptr = & b; we can also make cptr to point to the object d as follows: cptr = & d
  • 19. POINTERS TO DERIVED CLASS – CONT. Base Class Derived Class Public: a,b Public / Private / Private / Protected : Protected: c,d e,f,g,h If cptr = & d; cptr a,b
  • 20. POINTERS TO DERIVED CLASS – CONT. This shows that , although a base pointer can be made to point to any number of derived objects, it can not directly access the members defined by a derived class. To access the members defined by a derived class , cast base pointer to the derived class type.
  • 21. POINTERS TO DERIVED CLASS – CONT.  E.g . Casting dptr -> show ( ) ; ( ( DC * ) bptr ) -> show ( ) ;
  • 23. VIRTUAL FUNCTION The application of polymorphism is the ability to refer the objects without any regard to their classes. This necessitates the use of a single pointer variable to refer to the objects of different classes.
  • 24. VIRTUAL FUNCTION – CONT. By making the function 'virtual' in base class C++ determines which function to use at run time based on the type of object pointed to by the base pointer , rather than the type of the pointer. Runtime polymorphism is achieved only when a virtual function is accessed through a pointer to the base class.
  • 25. VIRTUAL FUNCTIONS - RULES 1. The virtual functions must be members of some class. 2. They cannot be static members. 3. They are accessed by using object pointers. 4. A virtual function can be friend of other function. 5. A virtual function in a base class must be defined , even though it may not be used.
  • 26. RULES –CONT. 6. We cannot have a virtual constructors, but we can have virtual destructors. 7. While a base pointer can point to any type of derived object, the reverse is not true.
  • 27. RULES –CONT. 8. The prototypes of the base class version of a virtual function and all the derived class versions must be identical. 9. When a base pointer points to a derived class , incrementing or decrementing it will not make it to point to the next object of the derived class.
  • 28. RULES –CONT. 10.If a virtual function is define in the base class ,it need not be necessarily redefined in the derived class.
  • 30. POLYMORPHISM  Polymorphism is crucial feature of Object Oriented Programming.  Polymorphism simply means one name having multiple forms.
  • 31. POLYMORPHISM - CONT.  “Polymorphism is the genie in OOP who takes instruction from clients and properly interprets their wishes.” – Ira Pohl, “Object Oriented Programming using C++”.
  • 32. POLYMORPHISM – CONT. Definition: Polymorphism is the ability to create a variable, a function or an object that has more than one form.
  • 33. EXAMPLE: For example: The + (plus) operator in C++: 4+5 <-- Integer addition 3.14 + 2.0 <-- Floating point addition s1 + "bar" <-- String concatenation!
  • 34. TYPES OF POLYMORPHISM Compile-time Run-time Polymorphism Polymorphism
  • 35. TYPES OF POLYMORPHISM  In compile time polymorphism, compiler is able to select the appropriate function a particular call at the compile time.  In run time polymorphism, an appropriate member function is selected while the program is running.
  • 36. BENEFITS OF POLYMORPHISM  Simplicity: This makes your code easier for you to write and easier for others to understand.  Extensibility: Polymorphism design and implements system that are more extensible.
  • 37. REFERENCES : Let us C++ – by Yeshwant Kanetkar. Object Oriented Programming with C++ –by E . BALAGURUSAMY. Internet.