13

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?

Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411
nitin_cherian
  • 6,405
  • 21
  • 76
  • 127

2 Answers2

27

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.

nitin_cherian
  • 6,405
  • 21
  • 76
  • 127
0

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.

littleadv
  • 20,100
  • 2
  • 36
  • 50
  • Yes out of curiosity. Is there an option in gcc to display the vtable? – nitin_cherian Jan 22 '12 at 07:08
  • @LinuxPenseur you must mean gdb. I don't know. I know that on Visual Studio I saw it appearing once in a while when I was inspecting classes. I guess it depends on what symbol gcc attaches to it and whether you can find that symbol. – littleadv Jan 22 '12 at 08:21