vtable for pure virtual function


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: vtable for pure virtual function

  1. #1
    Join Date
    Mar 2006
    Posts
    12

    Exclamation vtable for pure virtual function

    Hi,
    can any one help me what happens in vtable ?when i put a pure virtual function in a class. why we are not able to create obj for that class instead it get registered in vtable!!

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    It's quite a long story but in essence, a virtual table contains addresses of virtual functions of a given class. All objects of that class share the same virtual table. Each object has a pointer to that table, and when you call a virtual function, C++ looks it up in the table and launches it. You can think of a vtable is an array of pointers. Each virtual function has an index, and that index contains the memory address of that function. At compile time, each function call is translated to its matching index in the table and at runtime this value is retrieved from the table.
    Danny Kalev

  3. #3
    Join Date
    Mar 2006
    Posts
    12
    Thanks Danny, But is it means when i declear a virtual function in a class and creates object compiler didnt find address of function and since vtable is incomplete compiler throws error at compile time ? if i am wrong please correct me..
    Last edited by mailbox_abhishe; 10-17-2006 at 01:55 AM.

  4. #4
    Join Date
    Nov 2003
    Posts
    4,118
    The address is created once you declare the function, so you probably have a different error. Maybe a pure virtual function called? Anyway, please post the relevant code and the error message. It will be the easiest way to find out what the problem is.
    Danny Kalev

Similar Threads

  1. Getting a GUI to run
    By Eric in forum Java
    Replies: 4
    Last Post: 04-14-2006, 10:09 AM
  2. Packed Data(Comp-3, etc)
    By Marcos in forum VB Classic
    Replies: 3
    Last Post: 01-25-2006, 12:18 PM
  3. Getting a list of files into an array
    By Scott in forum VB Classic
    Replies: 12
    Last Post: 12-21-2001, 05:21 PM
  4. Getting a GUI to function
    By Eric in forum Java
    Replies: 1
    Last Post: 11-27-2001, 07:53 AM
  5. Trying to print a PDF File from VB
    By Kunal Sharma in forum VB Classic
    Replies: 2
    Last Post: 04-25-2000, 04:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center