際際滷

際際滷Share a Scribd company logo
Pure Virtual and Abstract
Date: 31st August 2020
By: Amit Kumar Trivedi
KHYATI SCHOOL OF COMPUTER APPLICATION
Introduction
Rules for virtual function
Internals of Virtual Functions
Pure virtual function
Virtual Base class
Virtual destructor
Abstract class
Limitations of virtual Function
Early binding v /s Late binding
Schedule
Start at : 10:07am
Break at 11 am for 7 minutes
Close at 11:50am
Rules for virtual function
Virtual functions must be members of some class.
Virtual functions cannot be static members.
They are accessed through object pointers.
They can be a friend of another class.
A virtual function must be defined in the base
class, even though it is not used.
Rules for virtual function
The prototypes of a virtual function of the base
class and all the derived classes must be identical. If
the two functions with the same name but different
prototypes, C++ will consider them as the
overloaded functions.
We cannot have a virtual constructor, but we can
have a virtual destructor
Pure virtual function
Pure virtual function can be defined as:
virtual void display() = 0;
Pure virtual function
A virtual function is not used for performing any task. It only serves as a
placeholder.
When the function has no definition, such function is known as "do-nothing"
function.
The "do-nothing" function is known as a pure virtual function.
A pure virtual function is a function declared in the base class that has no
definition relative to the base class.
A class containing the pure virtual function cannot be used to declare the
objects of its own, such classes are known as abstract base classes.
The main objective of the base class is to provide the traits to the derived
classes and to create the base pointer used for achieving the runtime
polymorphism.
Virtual Function
Virtual Base class
Dimond Problem
Pure virtual function and abstract class
Abstract class
Abstract Class is a class which contains atleast one Pure Virtual
function in it.
Abstract classes are used to provide an Interface for its sub classes.
Classes inheriting an Abstract Class must provide definition to the
pure virtual function, otherwise they will also become abstract
class.
Pure virtual function and abstract class
Limitations of virtual
Function
Practice
Create a Class Vehicle. Derived Class Car and
Truck. Chesis number is property of Vehicle class.
Function Drive.
I am driving car.
I am driving truck.
Demonstrate Dimond problem using this and
solution of it.
Make Drive pure virtual and Vechile as abstract
class
Early binding v /s Late
binding
Early Binding Late Bindning
Function
Overloading
Function
Overriding
Compile Time Run Time
Questions
Thank you

More Related Content

What's hot (20)

Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
Hitesh Kumar
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
Sivakumar R D .
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
Harsh Patel
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
Haresh Jaiswal
Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function
Kamlesh Makvana
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
[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
Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
Abhilash Nair
Constructors and Destructor in C++
Constructors and Destructor in C++Constructors and Destructor in C++
Constructors and Destructor in C++
International Institute of Information Technology (I族IT)
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
MOHIT AGARWAL
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
Vineeta Garg
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
Mauryasuraj98
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
Abstract class in java
Abstract class in javaAbstract class in java
Abstract class in java
Lovely Professional University
16 virtual function
16 virtual function16 virtual function
16 virtual function
Docent Education
Method overriding
Method overridingMethod overriding
Method overriding
Azaz Maverick
class and objects
class and objectsclass and objects
class and objects
Payel Guria
Access specifiers(modifiers) in java
Access specifiers(modifiers) in javaAccess specifiers(modifiers) in java
Access specifiers(modifiers) in java
HrithikShinde
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
Madishetty Prathibha
Inter Thread Communicationn.pptx
Inter Thread Communicationn.pptxInter Thread Communicationn.pptx
Inter Thread Communicationn.pptx
SelvakumarNSNS

Similar to Pure virtual function and abstract class (20)

Example for Virtual and Pure Virtual function.pdf
Example for Virtual and Pure Virtual function.pdfExample for Virtual and Pure Virtual function.pdf
Example for Virtual and Pure Virtual function.pdf
rajaratna4
Virtual function and abstract class
Virtual function and abstract classVirtual function and abstract class
Virtual function and abstract class
Shweta Shah
pure virtual function and abstract classes.ppt
pure virtual function and abstract classes.pptpure virtual function and abstract classes.ppt
pure virtual function and abstract classes.ppt
WaheedAnwar20
Virtual Functions | Polymorphism | OOP
Virtual Functions | Polymorphism | OOPVirtual Functions | Polymorphism | OOP
Virtual Functions | Polymorphism | OOP
shubham ghimire
object oriented programming language.pptx
object oriented programming language.pptxobject oriented programming language.pptx
object oriented programming language.pptx
syedabbas594247
Virtual function complete By Abdul Wahab (moon sheikh)
Virtual function complete By Abdul Wahab (moon sheikh)Virtual function complete By Abdul Wahab (moon sheikh)
Virtual function complete By Abdul Wahab (moon sheikh)
MoonSheikh1
Virtual Function
Virtual FunctionVirtual Function
Virtual Function
Lovely Professional University
Polymorphism
PolymorphismPolymorphism
Polymorphism
Prof .Pragati Khade
Introduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTXIntroduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTX
Syed Awais Mazhar Bukhari
6_VirtualFunctions_AbstractClasses.pdf
6_VirtualFunctions_AbstractClasses.pdf6_VirtualFunctions_AbstractClasses.pdf
6_VirtualFunctions_AbstractClasses.pdf
RamiDiab8
Understanding Framework Architecture using Eclipse
Understanding Framework Architecture using EclipseUnderstanding Framework Architecture using Eclipse
Understanding Framework Architecture using Eclipse
anshunjain
Polymorphism in C++
Polymorphism in C++Polymorphism in C++
Polymorphism in C++
Rabin BK
Jump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design Pattern
Nishith Shukla
Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design Patterns
Lalit Kale
Interface Vs Abstact
Interface Vs AbstactInterface Vs Abstact
Interface Vs Abstact
Anand Kumar Rajana
virtual function
virtual functionvirtual function
virtual function
VENNILAV6
Exploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App developmentExploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App development
Jayaprakash R
What is the meaning of the keyword this- Explain why it is valid only.docx
What is the meaning of the keyword this- Explain why it is valid only.docxWhat is the meaning of the keyword this- Explain why it is valid only.docx
What is the meaning of the keyword this- Explain why it is valid only.docx
dorisc7
6be10b153306cc41e65403247a14a4dba5f9186aCHAPTER 2_POINTERS, VIRTUAL FUNCTIONS...
6be10b153306cc41e65403247a14a4dba5f9186aCHAPTER 2_POINTERS, VIRTUAL FUNCTIONS...6be10b153306cc41e65403247a14a4dba5f9186aCHAPTER 2_POINTERS, VIRTUAL FUNCTIONS...
6be10b153306cc41e65403247a14a4dba5f9186aCHAPTER 2_POINTERS, VIRTUAL FUNCTIONS...
Mysteriousexpert
20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questions
Gradeup
Example for Virtual and Pure Virtual function.pdf
Example for Virtual and Pure Virtual function.pdfExample for Virtual and Pure Virtual function.pdf
Example for Virtual and Pure Virtual function.pdf
rajaratna4
Virtual function and abstract class
Virtual function and abstract classVirtual function and abstract class
Virtual function and abstract class
Shweta Shah
pure virtual function and abstract classes.ppt
pure virtual function and abstract classes.pptpure virtual function and abstract classes.ppt
pure virtual function and abstract classes.ppt
WaheedAnwar20
Virtual Functions | Polymorphism | OOP
Virtual Functions | Polymorphism | OOPVirtual Functions | Polymorphism | OOP
Virtual Functions | Polymorphism | OOP
shubham ghimire
object oriented programming language.pptx
object oriented programming language.pptxobject oriented programming language.pptx
object oriented programming language.pptx
syedabbas594247
Virtual function complete By Abdul Wahab (moon sheikh)
Virtual function complete By Abdul Wahab (moon sheikh)Virtual function complete By Abdul Wahab (moon sheikh)
Virtual function complete By Abdul Wahab (moon sheikh)
MoonSheikh1
6_VirtualFunctions_AbstractClasses.pdf
6_VirtualFunctions_AbstractClasses.pdf6_VirtualFunctions_AbstractClasses.pdf
6_VirtualFunctions_AbstractClasses.pdf
RamiDiab8
Understanding Framework Architecture using Eclipse
Understanding Framework Architecture using EclipseUnderstanding Framework Architecture using Eclipse
Understanding Framework Architecture using Eclipse
anshunjain
Polymorphism in C++
Polymorphism in C++Polymorphism in C++
Polymorphism in C++
Rabin BK
Jump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design Pattern
Nishith Shukla
Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design Patterns
Lalit Kale
virtual function
virtual functionvirtual function
virtual function
VENNILAV6
Exploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App developmentExploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App development
Jayaprakash R
What is the meaning of the keyword this- Explain why it is valid only.docx
What is the meaning of the keyword this- Explain why it is valid only.docxWhat is the meaning of the keyword this- Explain why it is valid only.docx
What is the meaning of the keyword this- Explain why it is valid only.docx
dorisc7
6be10b153306cc41e65403247a14a4dba5f9186aCHAPTER 2_POINTERS, VIRTUAL FUNCTIONS...
6be10b153306cc41e65403247a14a4dba5f9186aCHAPTER 2_POINTERS, VIRTUAL FUNCTIONS...6be10b153306cc41e65403247a14a4dba5f9186aCHAPTER 2_POINTERS, VIRTUAL FUNCTIONS...
6be10b153306cc41e65403247a14a4dba5f9186aCHAPTER 2_POINTERS, VIRTUAL FUNCTIONS...
Mysteriousexpert
20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questions
Gradeup

Recently uploaded (20)

FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptxFESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
DanmarieMuli1
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
POWERPOINT-PRESENTATION_DM-NO.017-S.2025.pptx
POWERPOINT-PRESENTATION_DM-NO.017-S.2025.pptxPOWERPOINT-PRESENTATION_DM-NO.017-S.2025.pptx
POWERPOINT-PRESENTATION_DM-NO.017-S.2025.pptx
MarilenQuintoSimbula
Research & Research Methods: Basic Concepts and Types.pptx
Research & Research Methods: Basic Concepts and Types.pptxResearch & Research Methods: Basic Concepts and Types.pptx
Research & Research Methods: Basic Concepts and Types.pptx
Dr. Sarita Anand
Mate, a short story by Kate Grenvile.pptx
Mate, a short story by Kate Grenvile.pptxMate, a short story by Kate Grenvile.pptx
Mate, a short story by Kate Grenvile.pptx
Liny Jenifer
Rass MELAI : an Internet MELA Quiz Finals - El Dorado 2025
Rass MELAI : an Internet MELA Quiz Finals - El Dorado 2025Rass MELAI : an Internet MELA Quiz Finals - El Dorado 2025
Rass MELAI : an Internet MELA Quiz Finals - El Dorado 2025
Conquiztadors- the Quiz Society of Sri Venkateswara College
Digital Tools with AI for e-Content Development.pptx
Digital Tools with AI for e-Content Development.pptxDigital Tools with AI for e-Content Development.pptx
Digital Tools with AI for e-Content Development.pptx
Dr. Sarita Anand
Kaun TALHA quiz Prelims - El Dorado 2025
Kaun TALHA quiz Prelims - El Dorado 2025Kaun TALHA quiz Prelims - El Dorado 2025
Kaun TALHA quiz Prelims - El Dorado 2025
Conquiztadors- the Quiz Society of Sri Venkateswara College
DUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAM
DUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAMDUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAM
DUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAM
vlckovar
N.C. DPI's 2023 Language Diversity Briefing
N.C. DPI's 2023 Language Diversity BriefingN.C. DPI's 2023 Language Diversity Briefing
N.C. DPI's 2023 Language Diversity Briefing
Mebane Rash
TPR Data strategy 2025 (1).pdf Data strategy
TPR Data strategy 2025 (1).pdf Data strategyTPR Data strategy 2025 (1).pdf Data strategy
TPR Data strategy 2025 (1).pdf Data strategy
Henry Tapper
How to attach file using upload button Odoo 18
How to attach file using upload button Odoo 18How to attach file using upload button Odoo 18
How to attach file using upload button Odoo 18
Celine George
APM People Interest Network Conference - Oliver Randall & David Bovis - Own Y...
APM People Interest Network Conference - Oliver Randall & David Bovis - Own Y...APM People Interest Network Conference - Oliver Randall & David Bovis - Own Y...
APM People Interest Network Conference - Oliver Randall & David Bovis - Own Y...
Association for Project Management
TRANSFER OF PATIENTS IN HOSPITAL SETTING.pptx
TRANSFER OF PATIENTS IN HOSPITAL SETTING.pptxTRANSFER OF PATIENTS IN HOSPITAL SETTING.pptx
TRANSFER OF PATIENTS IN HOSPITAL SETTING.pptx
PoojaSen20
Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1...
Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1...Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1...
Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1...
pinkdvil200
Kaun TALHA quiz Finals -- El Dorado 2025
Kaun TALHA quiz Finals -- El Dorado 2025Kaun TALHA quiz Finals -- El Dorado 2025
Kaun TALHA quiz Finals -- El Dorado 2025
Conquiztadors- the Quiz Society of Sri Venkateswara College
Information Technology for class X CBSE skill Subject
Information Technology for class X CBSE skill SubjectInformation Technology for class X CBSE skill Subject
Information Technology for class X CBSE skill Subject
VEENAKSHI PATHAK
How to Modify Existing Web Pages in Odoo 18
How to Modify Existing Web Pages in Odoo 18How to Modify Existing Web Pages in Odoo 18
How to Modify Existing Web Pages in Odoo 18
Celine George
Essentials of a Good PMO, presented by Aalok Sonawala
Essentials of a Good PMO, presented by Aalok SonawalaEssentials of a Good PMO, presented by Aalok Sonawala
Essentials of a Good PMO, presented by Aalok Sonawala
Association for Project Management
How to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of SaleHow to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of Sale
Celine George
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptxFESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
DanmarieMuli1
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
POWERPOINT-PRESENTATION_DM-NO.017-S.2025.pptx
POWERPOINT-PRESENTATION_DM-NO.017-S.2025.pptxPOWERPOINT-PRESENTATION_DM-NO.017-S.2025.pptx
POWERPOINT-PRESENTATION_DM-NO.017-S.2025.pptx
MarilenQuintoSimbula
Research & Research Methods: Basic Concepts and Types.pptx
Research & Research Methods: Basic Concepts and Types.pptxResearch & Research Methods: Basic Concepts and Types.pptx
Research & Research Methods: Basic Concepts and Types.pptx
Dr. Sarita Anand
Mate, a short story by Kate Grenvile.pptx
Mate, a short story by Kate Grenvile.pptxMate, a short story by Kate Grenvile.pptx
Mate, a short story by Kate Grenvile.pptx
Liny Jenifer
Digital Tools with AI for e-Content Development.pptx
Digital Tools with AI for e-Content Development.pptxDigital Tools with AI for e-Content Development.pptx
Digital Tools with AI for e-Content Development.pptx
Dr. Sarita Anand
DUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAM
DUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAMDUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAM
DUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAM
vlckovar
N.C. DPI's 2023 Language Diversity Briefing
N.C. DPI's 2023 Language Diversity BriefingN.C. DPI's 2023 Language Diversity Briefing
N.C. DPI's 2023 Language Diversity Briefing
Mebane Rash
TPR Data strategy 2025 (1).pdf Data strategy
TPR Data strategy 2025 (1).pdf Data strategyTPR Data strategy 2025 (1).pdf Data strategy
TPR Data strategy 2025 (1).pdf Data strategy
Henry Tapper
How to attach file using upload button Odoo 18
How to attach file using upload button Odoo 18How to attach file using upload button Odoo 18
How to attach file using upload button Odoo 18
Celine George
APM People Interest Network Conference - Oliver Randall & David Bovis - Own Y...
APM People Interest Network Conference - Oliver Randall & David Bovis - Own Y...APM People Interest Network Conference - Oliver Randall & David Bovis - Own Y...
APM People Interest Network Conference - Oliver Randall & David Bovis - Own Y...
Association for Project Management
TRANSFER OF PATIENTS IN HOSPITAL SETTING.pptx
TRANSFER OF PATIENTS IN HOSPITAL SETTING.pptxTRANSFER OF PATIENTS IN HOSPITAL SETTING.pptx
TRANSFER OF PATIENTS IN HOSPITAL SETTING.pptx
PoojaSen20
Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1...
Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1...Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1...
Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1...
pinkdvil200
Information Technology for class X CBSE skill Subject
Information Technology for class X CBSE skill SubjectInformation Technology for class X CBSE skill Subject
Information Technology for class X CBSE skill Subject
VEENAKSHI PATHAK
How to Modify Existing Web Pages in Odoo 18
How to Modify Existing Web Pages in Odoo 18How to Modify Existing Web Pages in Odoo 18
How to Modify Existing Web Pages in Odoo 18
Celine George
How to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of SaleHow to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of Sale
Celine George

Pure virtual function and abstract class

  • 1. Pure Virtual and Abstract Date: 31st August 2020 By: Amit Kumar Trivedi KHYATI SCHOOL OF COMPUTER APPLICATION
  • 2. Introduction Rules for virtual function Internals of Virtual Functions Pure virtual function Virtual Base class Virtual destructor Abstract class Limitations of virtual Function Early binding v /s Late binding
  • 3. Schedule Start at : 10:07am Break at 11 am for 7 minutes Close at 11:50am
  • 4. Rules for virtual function Virtual functions must be members of some class. Virtual functions cannot be static members. They are accessed through object pointers. They can be a friend of another class. A virtual function must be defined in the base class, even though it is not used.
  • 5. Rules for virtual function The prototypes of a virtual function of the base class and all the derived classes must be identical. If the two functions with the same name but different prototypes, C++ will consider them as the overloaded functions. We cannot have a virtual constructor, but we can have a virtual destructor
  • 6. Pure virtual function Pure virtual function can be defined as: virtual void display() = 0;
  • 7. Pure virtual function A virtual function is not used for performing any task. It only serves as a placeholder. When the function has no definition, such function is known as "do-nothing" function. The "do-nothing" function is known as a pure virtual function. A pure virtual function is a function declared in the base class that has no definition relative to the base class. A class containing the pure virtual function cannot be used to declare the objects of its own, such classes are known as abstract base classes. The main objective of the base class is to provide the traits to the derived classes and to create the base pointer used for achieving the runtime polymorphism.
  • 11. Abstract class Abstract Class is a class which contains atleast one Pure Virtual function in it. Abstract classes are used to provide an Interface for its sub classes. Classes inheriting an Abstract Class must provide definition to the pure virtual function, otherwise they will also become abstract class.
  • 14. Practice Create a Class Vehicle. Derived Class Car and Truck. Chesis number is property of Vehicle class. Function Drive. I am driving car. I am driving truck. Demonstrate Dimond problem using this and solution of it. Make Drive pure virtual and Vechile as abstract class
  • 15. Early binding v /s Late binding Early Binding Late Bindning Function Overloading Function Overriding Compile Time Run Time