Table of virtual methods

M

Milan Cermak

Hi all,
I have sort of philosophical question.
Contructor and destructor behavior points me to this.

Is table of virtual methods held in object?
Do I get it right that every created object has its own table of virtual
methods? Even if they are of one class?

Thanks for reactions,
Milan Cermak
 
H

Howard

Milan Cermak said:
Hi all,
I have sort of philosophical question.
Contructor and destructor behavior points me to this.

Is table of virtual methods held in object?

There is no specificationin the standard as to how the addresses of virtual
methods are stored.
Do I get it right that every created object has its own table of virtual
methods? Even if they are of one class?

No, that's not true. Whether they are virtual or not, the member functions
(and pointers to them in the case of virtual functions) only need to be
stored somewhere once per class (or struct) type. There's no need to copy
those for every object. That would be *very* wasteful.
 
J

John Harrison

Milan Cermak said:
Hi all,
I have sort of philosophical question.
Contructor and destructor behavior points me to this.

Is table of virtual methods held in object?
Do I get it right that every created object has its own table of virtual
methods? Even if they are of one class?

Typically each object holds a pointer to a table of virtual methods
(actually pointers to virtual methods). There is one table for each class,
and every object of the same class has the same pointer.

Multiple and virtual inheritance complicate this picture however.

If you are interested have a look at the book 'Inside the C++ Object Model'
by Stanley Lippman.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,476
Latest member
blackwatermelon

Latest Threads

Top