Virtual table is look up table for virtual functions. It contains the function pointer to the virtual functions. Virtual table is created for each class having one or more virtual function and classes derived from that class.virtual pointer better known as vptr containing the address of vtable is created for the most base class thats why size of empty class with virtual function is equal to the size of a pointer(8 bytes for a 64 bit computer)while size of a empty class without any virtual functions is only one byte.
Command to see
vtable/virtual table of a class.
Here if the name of the program is "classWithVf.cxx" so the command to see the vtable of the class is:
g++
-fdump-class-hierarchy classWithVf.cxx
#include<iostream>
using namespace std;
class M //empty
class
{
public:
void f() {}
};
class A //empty
class
{
int main()
{
// allocate memory for the string
//char *string1 = (char *) malloc(100*sizeof(char));
char *string1;
string1=new char;
// write some data to the string
strcpy(string1, "Hello String world xyz abcdef zxy!");
// display the string
//printf("%s\n", string1);
cout<<"String is:"<<string1<<endl;
// remove the string from memory
//delete string1;
return 0;
}