- 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
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
- Related Articles
- Difference between a virtual function and a pure virtual function in C++
- Difference Between Virtual and Pure Virtual Function
- Why do we need a pure virtual destructor in C++?
- Pure virtual destructor in C++
- What happens when a virtual function is called inside a non-virtual function in C++
- Pure Virtual Functions and Abstract Classes in C++
- Pure Function in C++
- Virtual Function in C++
- When do function-level static variables get initialized in C/C++?
- Inline virtual function in C++
- Why C++ does not have a virtual constructor?
- How is an array initialized in C#?
- How are C++ Local and Global variables initialized by default?
- What is meant by a pure-equity firm?
- Why are global and static variables initialized to their default values in C/C++?

Advertisements