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

  • Home
  • SEARCH
  • 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 1057505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:52:45+00:00 2026-05-16T17:52:45+00:00

Can some one explain me how inheritance is implemented in C++ ? Does the

  • 0

Can some one explain me how inheritance is implemented in C++ ?

Does the base class gets actually copied to that location or just refers to that location ?

What happens if a function in base class is overridden in derived class ? Does it replace it with the new function or copies it in other location in derived class memory ?

  • 1 1 Answer
  • 1 View
  • 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-16T17:52:46+00:00Added an answer on May 16, 2026 at 5:52 pm

    first of all you need to understand that C++ is quite different to e.g. Java, because there is no notion of a “Class” retained at runtime. All OO-features are compiled down to things which could also be achieved by plain C or assembler.

    Having said this, what acutally happens is that the compiler generates kind-of a struct, whenever you use your class definition. And when you invoke a “method” on your object, actually the compiler just encodes a call to a function which resides somewhere in the generated executable.

    Now, if your class inherits from another class, the compiler somehow includes the fields of the baseclass in the struct he uses for the derived class. E.g. it could place these fields at the front and place the fields corresponding to the derived class after that. Please note: you must not make any assumptions regarding the concrete memory layout the C++ compiler uses. If you do so, you’re basically on your own and loose any portability.

    How is the inheritance implemented? well, it depends!

    • if you use a normal function, then the compiler will use the concrete type he’s figured out and just encode a jump to the right function.
    • if you use a virtual function, the compiler will generate a vtable and generate code to look up a function pointer from that vtable, depending on the run time type of the object

    This distinction is very important in practice. Note, it is not true that inheritance is allways implemented through a vtable in C++ (this is a common gotcha). Only if you mark a certain member function as virtual (or have done so for the same member function in a baseclass), then you’ll get a call which is directed at runtime to the right function. Because of this, a virtual function call is much slower than a non-virtual call (might be several hundered times)

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

Sidebar

Related Questions

Can some one explain to me the difference between categories and inheritance in Objective
can some one explain why I face problem with backgroundworker backgroundWorker1_RunWorkerCompleted works just fine
Can some one explain the conceptual difference between both of them. Read somewhere that
Can some one explain what it means in simple terms. Does it mean the
Can some one explain to me how the SELECT return the results??. Does it
Can some one explain (or quote a reference) to compare the scoring mechanism used
Please can some one explain the javacv method for the pyrDown() method. I'm trying
Can some one please explain why this loop never 'breaks' and goes on forever
Can any one explain difference between position and anchor point in cocos-2D with some
Can some one explain Given a hash table array of size N=11., and using

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.