Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is the v-table created for a class?

I know that, how to implement virtual function call resolution is not part of C++ standrads nor it says anything about vptr or v-table, but let me ask this question here.

I've heard that v-table is a common technique used by compilers to implement virtual function call resolution. My understading about this is that there is only virtual table is needed per class, per process.

What I am wondering is, when is the v-table is created for a class?
Is it When the class of a given type (which needs a v-table) is created in a process space for the first time?
All other subsequently created objects of that type in that process space, refers to the v-table that is already created?
When would this v-table will be deleted?

I am sorry if this is too subjective or discussion type of question, but these questions lingers in my mind for a while and I feel its OK asking it here.

like image 644
riderchap Avatar asked Dec 17 '22 19:12

riderchap


1 Answers

The v-table is statically allocated and is never deleted, nor is it explicitly allocated. The pointers within any given specific object are constants.

like image 165
Puppy Avatar answered Jan 02 '23 21:01

Puppy