473,467 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

I am confused with VTable ;-)

Hi
I am new to C++ ,i really dont understand why there is a need for
VTable and can some experts give an example where exactly and how a compiler
uses it

Regards
Pani
Jul 19 '05 #1
2 2895

"Pani" <gn***********@siemens.com> wrote in message
news:bf**********@news.mch.sbs.de...
Hi
I am new to C++ ,i really dont understand why there is a need for
VTable and can some experts give an example where exactly and how a compiler uses it

Regards
Pani


Caution, this example may imply certain views about the theory of evolution
for which the author is completely irresponsible.

#include <iostream>
using namespace std;

class Ape
{
public:
virtual void what_am_i() { cout << "i'm an ape\n"; }
};

class Human : public Ape
{
public:
virtual void what_am_i() { cout << "i'm an human\n"; }
};

int main()
{
Ape* ape1 = new Ape();
Ape* ape2 = new Human();
ape1->what_am_i();
ape2->what_am_i();
}

Would you want to be mistaken for an ape?

Although ape2 has type Ape*, it is pointing to a Human object and therefore
a Human vtable. So the compiler uses the Human vtable to call
Human::what_am_i().

john
Jul 19 '05 #2

Pani wrote:

Hi
I am new to C++ ,i really dont understand why there is a need for
VTable and can some experts give an example where exactly and how a compiler
uses it


Try <http://www.codesourcery.com/cxx-abi/abi.html#vtable>.

regards,
alexander.
Jul 19 '05 #3

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...
6
by: Nolan Martin | last post by:
Hello, I was wondering if it were possible to access the vtable directly. Are there any resources that detail the inner workings of the vtable?
3
by: bp | last post by:
Hi, Could someone to tell me what I'm doing wrong? I'm using gcc version 3.3.4 and ld version 2.15.90.0.3 20040415 the linker message is: .../obj/classOpenAreaForm.o(.text+0x211): In...
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;
4
by: rahul8143 | last post by:
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...
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...
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...
10
by: Ole Nielsby | last post by:
James Kanze <james.kanze@gmail.comwrote: COM does rely on vtable layout. COM interfaces are declared as pure virtual classes, all methods using stdcall convention, and this works because most...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.