+ 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?
4 Respuestas
+ 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.
+ 8
Abstract classes are the ones which consists of pure virtual function.
+ 2
Sometimes to have a common parent of two different classes for which you don't need a concrete object.
0
Sonic hey can u please elaborate ? I didnt get it