C++ Programmer Question:
Tell us why pure virtual functions are used if they don't have implementation / When does a pure virtual function become useful?
Answer:
Pure virtual functions are used when it doesn't make sense to provide definition of a virtual function in the base class or a proper definition does not exists in the context of base class. Consider the above example, class SymmetricShape is used as base class for shapes with symmetric structure(Circle, square, equilateral triangle etc). In this case, there exists no proper definition for function draw() in the base class SymmetricShape instead the child classes of SymmetricShape (Cirlce, Square etc) can implement this method and draw proper shape.
Previous Question | Next Question |
Explain how to create a reference variable in C++? | Explain what is 'Copy Constructor' and when it is called? |