top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Why pure virtual functions are used and when does a pure virtual function become useful?

+2 votes
282 views
Why pure virtual functions are used and when does a pure virtual function become useful?
posted Mar 4, 2016 by Mohammed Hussain

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Briefly, it's to make the class abstract, so that it can't be instantiated, but a child class can override the pure virtual functions to form a concrete class. This is a good way to define an interface in C++.

for example:

if you have a class named SHAPE(where you can derived different types of shapes circle/square/triangle...)
And suppose SHAPE has function to calculate AREA. but you can't define AREA for every type of shape. That s why it is not implemented in the base class.

answer Mar 7, 2016 by Manikandan J
Similar Questions
0 votes

While doing design for a software, what things enforce to use template classes and template functions ?
Is it consider best practices or not ?

0 votes

Explain about pure virtual function

...