Explain virtual base classes,virtual function,pure virtual function? | Sololearn: Learn to code for FREE!

0

Explain virtual base classes,virtual function,pure virtual function?

c++

11/9/2016 6:31:02 PM

munish rastogi

1 Answer

New Answer

+1

* VIRTUAL BASE CLASSES got nothing to do with virtual functions , they're made virtual to avoid multiple inheritence problems * VIRTUAL FUNCTIONS are made virtual to provide the polymorphism capabilities of function in the base class pointer calling the last inheriting children function , it uses a vtable to so that * PURE VIRTUAL FUNCTIONS are virtual functions that do not have implementation in the base class but are needed in childrens classes , so to access it from the base pointer you can define them as empty (because they don't have to do nothing in the base class, but they have in the children's classes) , OR make it pure virtual to avoid any problems , and the base classs becomes therefore a prototype(model for the children's classes to implement it functions) that cannot be spawned