C++ Program to Create an Interface Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Interfaces are a feature of Java that allows us to define an abstract type that defines the behaviour of a class. In C++, there is no concept of interfaces, but we can create an interface-like structure using pure abstract classes. In this article, we will learn how to create interface-like structure in C++.Implementation of Interface in C++To create an interface, first we need to understand the rules that governs the behaviour of interface:Interface only contains the declaration of the methods not definition.Interface methods must be declared public.Any class can implement/inherit any interface.The implementing class must provide the definition of the methods.Instance of interface cannot be created.All of these rules can be followed by C++ pure abstract class that only contains the pure virtual functions. Following are the rules that governs the behaviour of pure abstract class:All methods of pure abstract class are only declared but not defined (pure virtual methods).Its methods can be defined either public, protected or private.Any class can inherit pure abstract class.The implementing class must provide the definition of the methods otherwise it will become abstract class.Instance of pure virtual class cannot be created.As we can see, we can almost perfectly simulate the Java Interfaces with C++ Pure Abstract Classes.Example C++ #include <bits/stdc++.h> using namespace std; // Interface equivalent pure abstract class class I { public: virtual string getName() = 0; }; // Class B which inherits I class B : public I { public: string getName() { return "GFG"; } }; // Class C which inherits I class C : public I { public: string getName() { return "GeeksforGeeks"; } }; int main() { B obj1; C obj2; I *ptr; // Assigning the address of obj1 to ptr ptr = &obj1; cout << ptr->getName() << endl; // Assigning the address of obj2 to ptr ptr = &obj2; cout << ptr->getName(); return 0; } OutputGFG GeeksforGeeks Explanation: The class I acts as an interface, declaring the pure virtual function getName() which must be implemented by any class that inherits from it. Classes B and C inherit from I and provide their own specific implementations of the getName() function, returning different strings. C++ Program to Create Interface Comment More infoAdvertise with us A akhilvasabhaktula03 Follow Improve Article Tags : C++ Programs C++ cpp-virtual cpp-inheritance C++ Misc Programs CPP-OOPs +2 More Practice Tags : CPP Explore C++ Programming Language 5 min read C++ OverviewIntroduction to C++ Programming Language 3 min read Features of C++ 5 min read History of C++ 7 min read Interesting Facts about C++ 2 min read Setting up C++ Development Environment 8 min read Difference between C and C++ 3 min read C++ BasicsUnderstanding First C++ Program 4 min read C++ Basic Syntax 4 min read C++ Comments 3 min read Tokens in C 4 min read C++ Keywords 2 min read Difference between Keyword and Identifier in C 3 min read C++ Variables and ConstantsC++ Variables 4 min read Constants in C 4 min read Scope of Variables in C++ 7 min read Storage Classes in C++ with Examples 6 min read Static Keyword in C++ 5 min read C++ Data Types and LiteralsC++ Data Types 7 min read Literals in C 4 min read Derived Data Types in C++ 4 min read User Defined Data Types in C++ 4 min read Data Type Ranges and Their Macros in C++ 3 min read C++ Type Modifiers 4 min read Type Conversion in C++ 4 min read Casting Operators in C++ 5 min read C++ OperatorsOperators in C++ 9 min read C++ Arithmetic Operators 4 min read Unary Operators in C 5 min read Bitwise Operators in C 6 min read Assignment Operators in C 4 min read C++ sizeof Operator 3 min read Scope Resolution Operator in C++ 4 min read C++ Input/OutputBasic Input / Output in C++ 5 min read cin in C++ 4 min read cout in C++ 2 min read Standard Error Stream Object - cerr in C++ 2 min read Manipulators in C++ 4 min read C++ Control StatementsDecision Making in C (if , if..else, Nested if, if-else-if ) 7 min read C++ if Statement 3 min read C++ if else Statement 3 min read C++ if else if Ladder 3 min read Switch Statement in C++ 5 min read Jump statements in C++ 4 min read C++ Loops 7 min read for Loop in C++ 6 min read Range-Based for Loop in C++ 3 min read C++ While Loop 3 min read C++ do while Loop 4 min read C++ FunctionsFunctions in C++ 8 min read return Statement in C++ 4 min read Parameter Passing Techniques in C 3 min read Difference Between Call by Value and Call by Reference in C 4 min read Default Arguments in C++ 5 min read Inline Functions in C++ 6 min read Lambda Expression in C++ 4 min read C++ Pointers and ReferencesPointers and References in C++ 5 min read C++ Pointers 8 min read Dangling, Void , Null and Wild Pointers in C 6 min read Applications of Pointers in C 4 min read Understanding nullptr in C++ 3 min read References in C++ 5 min read Can References Refer to Invalid Location in C++? 2 min read Pointers vs References in C++ 5 min read Passing By Pointer vs Passing By Reference in C++ 5 min read When do we pass arguments by pointer? 5 min read Like