Chapter 29 Flashcards
What are abstract classes
To implement an abstract concept. Abstract classes can not be instantiated. It can inherit.
how we define pure virtual function in c+++
virtual void draw() = 0;
Does not we need to use body of virtual function most often
Yes
Does the class having pure virtual function(s) becomes abstract and then it can not be instantiated.
Yes
What happened to derived class which base class has virtual function
Derived class also remain abstract until we make the virtual function non-pure. We do it by over-riding the virtual function(s) in base class and remove 0 from its deceleration.
Does order of execution of destructor reverse than constructor
Yes. First called derived class destructor, then its base class and then its base class.
Can we make the destructor virtual
Yes
What is the use of virtual functions
- To inherit interface and implementation
- Just inherit interface (pure virtual)
What is VTable
Compilers build a VTable (virtual function table) array for each class having virtual functions. A vtable array contains a pointer for each its associated virtual function.
How compiler deals with virtual functions and non-virtual functions
For non-virtual functions compiler just generate the code to call the function.
For virtual functions, compiler generates code to
- access the object
- access the VTable
- call the associated function.
Does polymorphism and virtual function a over head
Yes