Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > I am confused with VTable ;-)

Reply
Thread Tools

I am confused with VTable ;-)

 
 
Pani
Guest
Posts: n/a
 
      07-23-2003
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


 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      07-23-2003

"Pani" <(E-Mail Removed)> wrote in message
news:bflj8v$k3i$(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
 
Alexander Terekhov
Guest
Posts: n/a
 
      07-23-2003

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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
can some one please demystify vtable/vftable Paul C++ 1 06-24-2004 08:43 AM
HELP: wxValidator and undefined reference to `vtable ...` under linux Quansheng Liang C++ 2 05-25-2004 01:17 PM
type_info, vtable sks_cpp C++ 54 08-27-2003 03:57 PM
Undefined symbols: vtable for Foo r C++ 2 08-02-2003 08:18 PM
A::A[not-in-charge]() undefined reference to `vtable for A' Daniel Heiserer C++ 1 08-01-2003 04:05 PM



Advertisments