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 1062847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:41:32+00:00 2026-05-16T18:41:32+00:00

I heard lots of times virtual function is usually implemented using a vtable. But

  • 0

I heard lots of times virtual function is usually implemented using a vtable. But I actually don’t know actually how its implemented and how it works.

edit

I didn’t actually get this code: How can it be rewritten. Can someone explain this in detail please.

Finally, let’s see how the compiler implements a call to a virtual function. Your code might look like this:

 // Your original C++ code

 void mycode(Base* p)
 {
   p->virt3();
 }

The compiler has no idea whether this is going to call Base::virt3() or Der::virt3() or perhaps the virt3() method of another derived class that doesn’t even exist yet. It only knows for sure that you are calling virt3() which happens to be the function in slot #3 of the v-table. It rewrites that call into something like this:

 // Pseudo-code that the compiler generates from your C++

 void mycode(Base* p)
 {
   p->__vptr[3](p);
 }
  • 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-16T18:41:33+00:00Added an answer on May 16, 2026 at 6:41 pm

    The common implementation is to have one pointer at the beginning of every instance of an object that points to a vtable. There is one vtable per class, so if you have a class A and class B, there will be one table for each.

    The vtable essentially has a bunch of function pointers, so if class A has two virtual functions, foo() and bar(), the table will have pointers to both. If class B overrides those two functions, it will have its versions of foo() and bar() at the same offsets.

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

Sidebar

Related Questions

I know this question was asked million times but I used lots of advices
in the last times I heard lots of people claiming that the Cell processor
I heard lots of good opinions about Python language. They say it's mature, expressive
I heard about gems like faker or populator but they are a little bit
I don't know if it's simply because page-loads take a little time, or the
Lots of BAWs (big ass-websites) are using data storage and retrieval techniques that rely
I heard that it's possible to identify the brand of a device (or at
I heard that having @foreach inside of a view is a no-no. Meaning, the
I heard that Google can track all the static pages in a website and
I heard that you need to create images for both retina and non-retina. And

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.