C++ Interfaces


C++ Interfaces:

What are C++ interfaces?

  • An interface is a group of related functionalities that can belong to any class. The interfaces are created using abstract class.
  • Abstract classes are used to achieve the abstraction in C++ and abstraction in C++ is a process to hide the internal details and show functionality only.
  • The class can be made abstract by declaring at least one of its functions as pure virtual function. A pure virtual function is implemented with a virtual keyword and has =0 in its declaration and this function is called as abstract function as it has no body.

Let us have a look at the syntax:

virtual void function() = 0;

Let us have a look at the example to understand the abstract class:

Rules for abstract class

  • We can create a pointer and reference of base abstract class which points to the instance of child class.
  • It can have constructors.
  • Any class which has pure virtual function than that class is declared as abstract class.
  • We cannot create an object of abstract class.


Like it? Please Spread the word!