+ 2

What is the purpose of Abstract class in C++?

What us purpose of having abstract class with no function defination and having only pure virtual function?

20th Jul 2019, 3:59 AM
Amit chavare
Amit chavare - avatar
4 Answers
+ 1
An example: You have class shape with virtual functions Face and Perimeter. class Shape { public: virtual void Face()=0; virtual void Perimeter()=0; }; And you have two classes Square and Triangle. As you know square and triangle have diferent formulas for Face and for Perimeter. And that is why you need virtual functions. But there is no point to have object of class Shape, you can use this class only for base class of other classes, because when you say shape you can mean square or circle or something else. And that is why you need abstract class with pure virtual functions.
20th Jul 2019, 7:02 PM
B K
+ 8
Abstract classes are the ones which consists of pure virtual function.
21st Jul 2019, 3:55 AM
Manoj
Manoj - avatar
+ 2
Sometimes to have a common parent of two different classes for which you don't need a concrete object.
20th Jul 2019, 4:33 AM
Sonic
Sonic - avatar
0
Sonic hey can u please elaborate ? I didnt get it
20th Jul 2019, 5:14 AM
Amit chavare
Amit chavare - avatar