Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6848893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:55:27+00:00 2026-05-27T00:55:27+00:00

vtable is an overhead in all base/derived classes when a base class has a

  • 0

vtable is an overhead in all base/derived classes when a base class has a virtual function. vtable is supposed to contain an array of function pointers to these virtual functions. Also vtable is “one per class” as opposed to “one per object”.

Now imagine an object of such a class being created. It’ll get a fresh copy of virtual functions of the class in some memory location by the runtime. Since vtable is a collection of function pointers it’ll be updated to reflect this. If another object of the same class is created then it’ll again have a fresh copy of the virtual functions in some other memory location

Since vtable is “one per class” and not “one per instance” how will it point to correct location for different instances?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:55:28+00:00Added an answer on May 27, 2026 at 12:55 am

    It’s simple… the vftable itself is one-per-class, the pointer is one-per-instance. Two instances of the same type will have their vftable pointer pointing to the same location.

    class A
    {
       virtual void foo();
       virtual void goo();
    }
    
    class B : public A
    {
       virtual void foo();
    }
    

    In memory, you will have:

    vftable for A:  
    
    +----------+---------+
    |   0x01   |  0x02   |
    +----------+---------+
      &A::foo()  &A::goo()
    
    vftable for B:
    
    +----------+---------+
    |   0x11   |  0x12   |
    +----------+---------+
      &B::foo()  &A::goo()
    

    Assume you create two objects:

    A a;
    B b;
    

    a’s first member will be:

    vftableptr: 0x01
    

    b’s first member will be

    vftableptr: 0x11
    

    In general, polymorphism is implemented getting the address of the vftable, adding the function offset (for example, if we call goo(), the offset is 1), and jumping to that location. Since the objects are of different types, they will point to different locations, although the vftables (which are different) can contain similar members.

    IMPORTANT NOTE: values are bogus, the offset isn’t 1 nor the addresses 0x01 etc., I chose them to make a point.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If we write virtual function it adds a vtable in object of that class.
I need to call the co-class function by reading its address from vtable of
I know in C++ there are vpointer and vtable. The virtual function table is
I'm creating a Browser Helper Object using VS2008, C++. My class has been derived
If a Base class does not have a virtual destructor (in order to avoid
Further to my question: Detect the the vtable offset of a specific virtual function
Is the vtable only used for virtual function lookups, or does it get used
I heard lots of times virtual function is usually implemented using a vtable. But
Lets say there is a class named Person which contains a virtual function named
When I try to create a class instance with a virtual method and pass

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.