Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does every class have virtual function table in C++

Tags:

c++

vtable

Does every class have virtual function table in C++?

I know virtual table is for polymorphism. Class with virtual functions must have v-table. But how about class has no virtual function? Or how about class has no base class?

like image 466
Anders Lind Avatar asked Jul 05 '26 22:07

Anders Lind


1 Answers

The language specification of C++ does not define what a "vtable" is, or which classes need one.

A particular implementation of C++ in a compiler often uses a vtable to implement virtual methods. If a class has no virtual methods (and no superclasses with virtual methods), then the compiler may omit the vtable. However, keep in mind this is purely a compiler implementation decision, and not required by the standard.

like image 71
Greg Hewgill Avatar answered Jul 08 '26 14:07

Greg Hewgill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!