nitin_cherian
nitin_cherian

Reputation: 6675

How to display the VTABLE of a C++ class through GCC?

I understand that a class will have a VTABLE, if it contains at-least one virtual function. I would like to see the contents of the VTABLE. Is there a way to display it ?

Specifically, is there an option in gcc to display the VTABLE of a class?

Upvotes: 14

Views: 8455

Answers (2)

nitin_cherian
nitin_cherian

Reputation: 6675

If the input file is say layout.cpp, the command gcc -fdump-class-hierarchy layout.cpp will produce a file layout.cpp.class. This file will display the VTABLE along with some other useful information.

Upvotes: 29

littleadv
littleadv

Reputation: 20282

Assuming it will really have a v-table (this is compiler dependent, and is not required or dictated by the standard) - you can inspect it with your debugger.

Why would you do that? If you're relying on it for anything other than curiosity - then don't.

Upvotes: -1

Related Questions