C Example Abstract Class - C

How to use abstract class in C language?

Snippet Code


  
Rate this page :
  [ 0 votes]

Abstract class is class which contain more abstract methods. Abstract method is declared only in an abstract class. Important point is abstract class cannot be instantiated, but pointers and references of Abstract class type can be created. C is not an object oriented language so abstract classes are used through cpp programming. The below code is an example for abstract class in cpp.

#include <iostream> using namespace std; class abstractclass { public: virtual void show() = 0; }; class Derived:public abstractclass { public: void show() { cout << "Implementation of Virtual Function in Derived class"; } }; int main() { abstractclass *b; Derived d; b = &d; b->show(); }

Tags


Ask Questions

Ask Question