
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Why Is a C++ Pure Virtual Function Initialized by 0
It’s just a syntax, nothing more than that for saying that “the function is pure virtual”.
A pure virtual function is a virtual function in C++ for which we need not to write any function definition and only we have to declare it. It is declared by assigning 0 in declaration.
Here is an example of pure virtual function in C++ program
Example Code
#include<iostream> using namespace std; class B { public: virtual void s() = 0; // Pure Virtual Function }; class D:public B { public: void s() { cout << " Virtual Function in Derived class\n"; } }; int main() { B *b; D dobj; b = &dobj; b->s(); }
Output
Virtual Function in Derived class
Advertisements