Answer Posted / deepa balamurugan
If the both Base and the Derived class having the same
function then the Base class funtion should be declared as
virtual function. Then the C++ determines which function to
be called at the runtime based on the type of the object
pointed to by the Base pointer rather than the type of the
pointer.
As soon as the compiler reads the keyword virtual ,it will
create the vtable contains the address of the virtual
function inside that class and as soon as vtable is
created ,vptr is initialized to the proper vtable.
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
How do I tokenize a string in c++?
What are the implicit member functions of class?
If a base class declares a function to be virtual, and a derived class does not use the term virtual when overriding that class, is it still virtual when inherited by a third-generation class?
What is meant by entry controlled loop?
Should you pass exceptions by value or by reference?
How a pointer differs from a reference?
What is setw manipulator in c++?
How would you find out if a linked-list is a cycle or not?
When the constructor of a base class calls a virtual function, why doesn't the override function of the derived class gets called?
What is the difference between a definition and a declaration?
What is the v-ptr?
What are c++ templates used for?
What are friend classes?
How much do c++ programmers make?
What is expression parser in c++