- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference Between Virtual and Pure Virtual Function
In this post, we will understand the difference between virtual and pure virtual functions.
Virtual Function
It has its own definition inside the class.
The base class can override a virtual function.
It doesn’t have a derived class.
Declaration
virtual funct_name(parameter_list) {. . . . .};
Pure Virtual Function
It doesn’t have a definition.
If a class has at least one virtual function, it can be declared abstract.
The derived class has to override the pure virtual function to use it.
A pure virtual function is specified by placing "= 0" in its declaration
Declaration
virtual funct_name(parameter_list)=0;
Following is an example −
Example
class Box { public: // pure virtual function virtual double getVolume() = 0; private: double length; // Length of a box double breadth; // Breadth of a box double height; // Height of a box };
- Related Articles
- Difference between a virtual function and a pure virtual function in C++
- Pure virtual destructor in C++
- Why is a C++ pure virtual function initialized by 0?
- Difference between Virtual memory and Cache memory
- Difference between Cache Memory and Virtual Memory
- Difference Between Real Image and Virtual Image
- Pure Virtual Functions and Abstract Classes in C++
- Difference Between Virtual Private Network (VPN) and Proxy
- Difference Between Virtual and Cache Memory in OS
- Difference between a Virtual Office and Physical Office
- Virtual Function in C++
- What is the difference between Augmented Reality and Virtual Reality?
- What is the difference between Real Image and Virtual Image?
- Default arguments and virtual function in C++
- What is the difference between virtual and abstract functions in C#?

Advertisements