473,472 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

What happens to VTABLE when base class has virtual function and derived class does?

2 New Member
If derived class will be having vtable then why we need vtable for derived class?
Jul 18 '10 #1
3 2206
weaknessforcats
9,208 Recognized Expert Moderator Expert
The vtable identifies what function to call when you call a virtual function on an object.

Every class has a vtable if that class has a virtual function.

In your case, base objects have a vtable that will call the base class version of the virtual function. Derived objects will have a vtable that calls the derived class version of the virtual function.

If there is no derived class version of the virtual function, then the derived class vtable will call the base class version of the virtual function.
Jul 18 '10 #2
abhi97
2 New Member
ok. my question is why derived class will be having the vtable. if we see in other word, derived class does not have any virtual function then why vtable?
Jul 21 '10 #3
Joseph Martell
198 Recognized Expert New Member
If the base class does NOT have a virtual function and the derived class does NOT have a virtual funciton, then neither class gets a vtable.

If the base class has a virtual function, then the derived class has a virtual function, whether the virtual keyword is used or not. Virtual functions don't go away after a class has been inherited.
Jul 21 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Webster | last post by:
Hello, I have a class Shape and subclasses Circle, Rectangle etc. I also have a function to write them to a file given a filepointer. However, I store the colour info in the Shape class. My...
3
by: J.J. Feminella | last post by:
(Please disregard the previous message; I accidentally sent it before it was completed.) I have source code similar to the following. public class Vehicle { protected string dataV; // ......
7
by: Baski | last post by:
Base class: class AssetBase { string _clli; public string CLLI { get
1
by: Mark McDonald | last post by:
This question kind of follows on from Mike Spass’ posting 10/11/2004; I don’t understand why you can’t declare an implicit operator to convert a base class to a derived class. The text...
2
by: mac_ferrari1975 | last post by:
Hi all, Consider the situation. I am designing class library and I have a class A. I derived class B and class C from A but derivation is not virtual. for exa. class A {}; class B : public A...
6
by: Hubert Fritz | last post by:
Hello, I fear I want to have something which is not possible in C++. How is it possible to define a base class so that the derived class is forced to contain a static member variable, which...
2
by: Ethan Strauss | last post by:
Hi, I want to be able to make a Master constructor for a class which all overloads of the class constructor would call and thus if I have minor changes to something I only need to make them in the...
11
by: Rahul | last post by:
Hi Everyone, While working with Java, i came across super() which passes values to base class constructor from derived class constructor. I was wondering if this could be implemented in c++ by...
14
by: Jack | last post by:
Hi, I meet a question with it , I did not get clear the different betteen them, for example: #include <iostream>
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.