How the V-Table mechanism works?

Answers were Sorted based on User's Feedback



How the V-Table mechanism works?..

Answer / dee

V-table is created for class when a class has atleast one
virtual function and each virtual function has a entry in
the V-table.

Is This Answer Correct ?    48 Yes 3 No

How the V-Table mechanism works?..

Answer / nishikant sahu

V-Table holds the addresses of virtual functions of a class
and type_info structure for RTTI.V-table created class basis.
when an object created compiler secretly inserted the
v-table pointer of the respective class and then Vptr
iterator accordingly. all are done under the hood.

Is This Answer Correct ?    21 Yes 3 No

How the V-Table mechanism works?..

Answer / ramesh

V-table is specific to class. No matter how many objects
are created for this class, only one virtual table exists.
Each virtual function in the class will have a pointer in
Vtable.

Whenever a code like Base *b = new Derived; is encountered,
during compile time the search will happen in Base class.
Its only during run time the actual objects are invoked and
the fucntion present in derived class will be called.

Is This Answer Correct ?    6 Yes 1 No

How the V-Table mechanism works?..

Answer / 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

How the V-Table mechanism works?..

Answer / tiru

virtual table contains the address of the virtual functions
and pointers to the objects of the each of the derived
classes.

Is This Answer Correct ?    6 Yes 12 No

How the V-Table mechanism works?..

Answer / achal

V-Table mechanism works on principle of dynamic binding
i.e. which version of the function has to be called is
decided by CPU at run time.
Use of virtual functions make the execution slower. Not all
the objects of the same class have different V-Table.

Is This Answer Correct ?    2 Yes 10 No

Post New Answer

More C++ General Interview Questions

What is multithreading and what is its use?Whats are multithreading techniques used in C++?

1 Answers  


What is std namespace in c++?

0 Answers  


Differentiate between the manipulator and setf( ) function?

0 Answers  


A prime number is a number which is divisible only by itself and 1. Examples of the first few primes are 2, 3, 5, 7, 11. Consider writing a program which can generate prime numbers for you. Your program should read in and set a maximum prime to generate and a minimum number to start with when looking for primes. This program should be able to perform the following tasks: 1. Read the maximum number from user (keyboard input) to look for primes. The program should not return any primes greater than this number. 2. Read the minimum number from user (keyboard input) to look for primes. The program should not return any primes less than this number. 3. Generate and print out every prime number between the maximum prime and minimum number specified by the user.

0 Answers  


Why is it called c++?

0 Answers  






what is an array

20 Answers  


Is facebook written in c++?

0 Answers  


What does 7/9*9 equal ? a) 1 b) 0.08642 c) 0

0 Answers  


What is the difference between struct and class?

1 Answers  


How a macro differs from a template?

0 Answers  


How to access a variable of the structure?

0 Answers  


Is it possible to have a recursive inline function in c++?

0 Answers  


Categories