How to Create a Pure Virtual Function in C++? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In C++, pure virtual functions are those functions that are not implemented in the base class. They are instead implemented in the derived classes if necessary. In this article, we will discuss how to create a pure virtual function in a class in C++. How to Create a Pure Virtual Function in C++? To declare a member function as a pure virtual function, we can use the following syntax: virtual function_name (arguements) {} = 0; Classes that contain at least one pure virtual function are called abstract classes. If we don't implement the pure virtual function in the derived class, then the derived class also becomes the abstract class and we cannot instantiate it. C++ Program to Implement a Pure Virtual Function C++ // C++ Program to demonstrate how to create a pure virtual // function #include <iostream> using namespace std; // Abstract base class with a pure virtual function class AbstractBase { public: // Pure virtual function virtual void pureVirtualFunction() const = 0; // Non-pure virtual function with an implementation void nonPureVirtualFunction() const { cout << "This is a non-pure virtual function.\n"; } }; // Derived class implementing the pure virtual function class Derived : public AbstractBase { public: // Implement the pure virtual function void pureVirtualFunction() const override { cout << "Derived class implementing the pure " "virtual function.\n"; } }; int main() { // AbstractBase base; // Error: Cannot instantiate an // object of an abstract class // Create an object of the derived class Derived derivedObj; // Call the pure virtual function through the derived // class object derivedObj.pureVirtualFunction(); // Call the non-pure virtual function with an // implementation derivedObj.nonPureVirtualFunction(); return 0; } OutputDerived class implementing the pure virtual function. This is a non-pure virtual function. Comment A arivashiscqxq Follow 0 Improve A arivashiscqxq Follow 0 Improve Article Tags : C++ Programs C++ C++-Virtual Functions CPP-OOPs CPP Examples +1 More Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like