Sunday, 30 June 2013

what is a VTABLE

A Vtable contains the address of the virtual functions. The compiler creates a VTABLE for each that contains virtual functions and for classes that are derived from it. The VATABLE contains virtual functions and for classes that are derived from it. The VTABLE contains the address in the order in which virtual function are defined within the class .

Let us understand the  VTABLE with the help of the following example

class Cshape
{
     public:
           virtual void draw1()
           {
       
            }

         virtual  void draw2()
         {
       
          }
};

class circle : public shape
{
   public:
     void draw1()
      {
     
      }
 
     void draw2()
      {
         
      }
};

void main()
{

      shape *P, q;
      circle c;
      p = &q;
      p->draw2();
      p = &c;
      p->draw2();
}

whenever we create an object of the class, the  class gets loaded in to the memory and vtable gets created.

        
        
                 
      


0 comments:

Post a Comment