473,383 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

VTABLE virtual function in derived class

hello,
what happens to VTABLE when base class has virtual function and
derived class does not override it? Does derived class also builds
VTABLE if it has no functions?
eg. if code is like this(only demo code)
class a{
public:
virtual void fun()
{
cout<<"Base class";
}
};
class d:public a
{
};

int main()
{
d obj;
return 0;
}

Aug 23 '05 #1
4 3016

rahul8...@gmail.com wrote:
hello,
what happens to VTABLE when base class has virtual function and
derived class does not override it? Does derived class also builds
VTABLE if it has no functions?


Why do you care?

In a typical implementation vtables are generated one per class by a
compiler at compile stage and stored in a read only segment of your
binary. Thus, no runtime vtable building occurs. A class instance bears
only a pointer to its vtable. Upon entering a constructor compiler
injected code sets the vtable pointer to a proper vtable.

Aug 23 '05 #2

Maxim Yegorushkin wrote:
rahul8...@gmail.com wrote:
hello,
what happens to VTABLE when base class has virtual function and
derived class does not override it? Does derived class also builds
VTABLE if it has no functions?
Why do you care?

In a typical implementation vtables are generated one per class by a
compiler at compile stage and stored in a read only segment of your
binary.

Does that mean if i have 3 classes base1, derived1, derived2 then
each one has VTABLE provided all are usinf virtual functions?Thus, no runtime vtable building occurs. A class instance bears that mean derived class also builds VTABLE at compile time then is
address od virtual function be same for base1 and derived1 if base1 has
virtual function and derived1 has no overridden function? only a pointer to its vtable. Upon entering a constructor compiler
injected code sets the vtable pointer to a proper vtable.


Aug 23 '05 #3

ra*******@gmail.com wrote:
Maxim Yegorushkin wrote:
rahul8...@gmail.com wrote:
hello,
what happens to VTABLE when base class has virtual function and
derived class does not override it? Does derived class also builds
VTABLE if it has no functions?
Why do you care?

In a typical implementation vtables are generated one per class by a
compiler at compile stage and stored in a read only segment of your
binary. Does that mean if i have 3 classes base1, derived1, derived2 then
each one has VTABLE provided
Yes. A compiler may optimize out a vtable for a derived class if it
does not overload any virtual functions so that its base class's vtable
is fine.
all are usinf virtual functions?
Did not understand this part.
Thus, no runtime vtable building occurs. A class instance bears that mean derived class also builds VTABLE at compile time then is
address od virtual function be same for base1 and derived1 if base1 has
virtual function and derived1 has no overridden function?


Yes.
only a pointer to its vtable. Upon entering a constructor compiler
injected code sets the vtable pointer to a proper vtable.


Aug 23 '05 #4

Maxim Yegorushkin wrote:

[]
that mean derived class also builds VTABLE at compile time then is
address od virtual function be same for base1 and derived1 if base1 has
virtual function and derived1 has no overridden function?


Yes.


Well, I am wrong here when multiple inheritance comes in. You might
find this illuminating http://files.rsdn.ru/4539/cud94.htm

Aug 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Quansheng Liang | last post by:
Hello, I struggled with the problem of "undefined reference to `vtable ...`" while migrating a project from windows to linux. After searching the google I removed all the inline functions and now...
7
by: Karl Ebener | last post by:
Hi! I have created a program using several classes with inheritage. When I compile and link, I get the following error: :$ g++ service2.cpp Service.cpp Application.cpp Message.cpp...
4
by: Clint Ruen | last post by:
Hello all, I have written out a data structure using the binary flag on an ofstream. The struct/class is something like this class SomeData { public: int data1;
9
by: jimjim | last post by:
Hello all, class Base { public: virtual void f(); }; class Derived : public Base{ private: int i; };
9
by: kish_nand | last post by:
Could someone please explain me the concept behind virtual functions and vtables. I am little confused about this. Please refer to the following code and tell me how many virtual tables would be...
17
by: ypjofficial | last post by:
Hello All, I have read in many c++ literature that vtable is nothing but an array of pointer to virtual functions inside a class.And the class where the virtual function/s are declared stores the...
9
by: schand | last post by:
How does the virtual table accessed in MMU based system?
5
by: druberego | last post by:
I read google and tried to find the solution myself. YES I do know that you can get undefined references if you: a) forget to implement the code for a prototype/header file item, or b) you forget...
3
by: chaturap | last post by:
Hi, I'm trying to implement factory method pattern using C++ on Ubuntu 8.04 using gcc 4.2. There are 3 major classes DBConnectionFactory, DBConnector and OracleConnector (which is the derived...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.