C++ Programmer Question:

Download Job Interview Questions and Answers PDF

Tell us why pure virtual functions are used if they don't have implementation / When does a pure virtual function become useful?

C++ Programmer Interview Question
C++ Programmer Interview Question

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.

Download C++ Programmer Interview Questions And Answers PDF

Previous QuestionNext Question
Explain how to create a reference variable in C++?Explain what is 'Copy Constructor' and when it is called?