+ 2
What is a pure virtual function?
Pure virtual functions are virtual function with no definition. for example: virtual void func() =0;
3 ответов
+ 1
A pure virtual function has no body and it's characterized by the =0 in its declaration.
Such functions must be overridden in the derived class.
0
Pure virtual functions are the virtual functions that are undefined in their base class and user of the base class define it in derived class as per the specifications of derived class.
- 1
class Shape {
protected:
int width, height;
public:
Shape( int a=0, int b=0)
{
width = a;
height = b;
}
// pure virtual function
virtual int area() = 0;
};
The = 0 tells the compiler that the function has no body and above virtual function will be called pure virtual function.